0

I´m using code first, a database with about 60 tables, the error on the title occurs on 3 tables and i dont understand why...

int count_manual = db.Database.SqlQuery<int>("select  count(*) from My_Table").Single(); // This works

int count = db.My_Table.Count(); // this throws an exception

The exception I´m getting is "The entity set or function import 'My_Table' is not defined in the entity container 'My_Context'"

This is my bdset

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

This is the only reference i have in the My_Context class fro My_Table (including case sensitive checks).

If i change the variable name to anything else, it works. Example:

public DbSet<My_Table> My_Table_1 { get; set; }

My model creating is overriden:

 protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        base.OnModelCreating(modelBuilder);

        modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
        modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
    }

I am unable to find anything wrong, does anyone has a clue what i might be missing?

Sergio
  • 8,125
  • 10
  • 46
  • 77
  • There is obviously a name clash. The property has the same name as the entity class and it appears to give EF trouble. It's a `DbSet` so it makes sense to pluralize it anyways so why not just call it `My_Tables`? – JuanR Oct 30 '17 at 18:39
  • This convention is used on all tables in the project (fails on 3 out of 71 tables). Has i stated in the question, i know that renaming the property solves the problem, i just don't know why. Doesn't make sense. – Sergio Oct 31 '17 at 08:08

0 Answers0