Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework added s to my .dbo

I using "Entity Framework DbContext" at the moment I have got exception towars.dbo was not found. This is very strange because in my website I all the time ask about towar.dbo but no towars.dbo Do you know where is a problem?

- InnerException    {"Invalid object name 'dbo.Towars'."}   System.Exception {System.Data.SqlClient.SqlException}

My all things about Towar (of course different place in my program):

public class ProductController : Controller
{
    //
    // GET: /Product/
        public ITowarRepository repository;

        public ProductController(ITowarRepository productRepository) 
        {
        repository = productRepository;
        }

        public ViewResult List()
        {
            return View(repository.Towar);
        }

}


public interface ITowarRepository
    {
        IQueryable<Towar> Towar { get; }
    }

public DbSet<Towar> Towar { get; set; }

public class EFTowarRepository : ITowarRepository
    {
        public EFDbContext context = new EFDbContext();
        public IQueryable<Towar> Towar
        {
            get { return context.Towar; }
        }
    }
public class Towar
    {
        [Key]
        public int Id_tow { get; set; }
        public string Nazwa { get; set; }
        public string Opis { get; set; }
        public decimal Cena { get; set; }
        public int Id_kat { get; set; }
    }
like image 601
RPD Avatar asked Aug 03 '12 15:08

RPD


People also ask

Is Entity Framework connected or disconnected?

There are 2 ways (connected and disconnected) when persisting an entity with the Entity Framework. Both ways have their own importance. In the case of a connected scenario the changes are tracked by the context but in the case of a disconnected scenario we need to inform the context about the state of the entity.

Where does the Entity Framework fits in your application?

As per the above figure, Entity Framework fits between the business entities (domain classes) and the database. It saves data stored in the properties of business entities and also retrieves data from the database and converts it to business entities objects automatically.


1 Answers

Add the following line to your context:

modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
like image 133
Forty-Two Avatar answered Nov 16 '22 00:11

Forty-Two