While working with EF code first I get error given below at different times:
The entity type SomeType is not part of the model for the current context.
What are the possible causes of this error?
While working with EF code first I get error given below at different times:
The entity type SomeType is not part of the model for the current context.
What are the possible causes of this error?
I've been doing database first and using the built in template generation for my models (EF 4.1)
I copied the generated code into a new file and removed the navigation properties. That's when I started to see this error. I have lazy loading turned off, but it appears the navigation properties are still necessary in the POCO's.
I suppose the error might indicate that your model is missing something.
The above code shows the navigation properties commented out. If I uncomment them on all POCO's (that means the Role POCO too) the exception goes away.
UPDATE
This error kept attacking me with various updates I made to the database. Eventually I deleted the edmx file and just created it again with the same tables and stored procs.
Old
I got this when the generated entity was missing a nullable column:
I added the property after generating the initial model. However, I even tried deleting the table and recreating it. That didn't fix it. Only adding the property manually fixed it for me.
It may occur because:
It may happen when your model is not mapped correctly to your Class. In my case I got this error when I used EF Model First and when I updated my EDMX model from DB but didn't update my Entity class. Specifically a property in Entity was in lower case while in DB and EDMX diagram was in Upper case. And another issue I had was a model property in EDMX diagram was not converted to my app Enum So that EF couldn't recognize that Entity.