The entity type <type> is not part of the model for the current context
Put this in your custom DbContext
class:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Estate>().ToTable("Estate");
}
If your tables are not created on startup, this is why. You need to tell the DbContext about them in the OnModelCreating method override.
You can either do custom per-entity mappings here, or separate them out into separate EntityTypeConfiguration<T>
classes.
Apparently, this error is very generic, it could have a number of reasons. In my case, it was the following: The connection string (in Web.config) generated by the .edmx
was invalid. After almost a day of trying everything, I changed the connection string from the EF string to an ADO.NET string. This solved my issue.
For example, the EF string looks something like this:
<connectionStrings>
<add name="BlogContext"
connectionString="metadata=res://*/BloggingModel.csdl|
res://*/BloggingModel.ssdl|
res://*/BloggingModel.msl;
provider=System.Data.SqlClient
provider connection string=
"data source=(localdb)\v11.0;
initial catalog=Blogging;
integrated security=True;
multipleactiveresultsets=True;""
providerName="System.Data.EntityClient" />
</connectionStrings>
And the ADO.NET string looks like this:
<connectionStrings>
<add name="BlogContext"
providerName="System.Data.SqlClient"
connectionString="Server=.\SQLEXPRESS;Database=Blogging;
Integrated Security=True;"/>
</connectionStrings>
Source: http://msdn.microsoft.com/nl-nl/data/jj556606.aspx
For me the issue was that I had not included the Entity Class within my db set inside the context for entity framework.
public DbSet<ModelName> ModelName { get; set; }