EF6 model first - The entity type is not part of the model for the current context

entity-framework entity-framework-6


I know questions about this issue have already been asked dozens of times (I've read them all) but I am still left with no solution. Most deal with issues that can happen with code-first design, but I am doing model-first.

I am familiar with EF, and have other working models in my solution.

  • WPF (net 4.5)
  • Entity Framework 6.1.3 - Model First
  • Visual Studio 2013


Every DbSet<> in my context throws the following error when being accessed:

"An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code

Additional information: The entity type xxx is not part of the model for the current context. "

How I created the model:

  1. new project
  2. add edmx - include tables model first
  3. made the entities inherit from a base class that implements INotifyPropertyChanged
  4. removed the base class and modified the .tt file so the entities implement INotifyPropertyChanged instead
  5. (Deleted everything and tried again from scratch)

Connection String:

<add name="Stratus_X_TestEntities" connectionString="metadata=res://*/PartsServiceModel.csdl|res://*/PartsServiceModel.ssdl|res://*/PartsServiceModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=Stratus;initial catalog=StratusX;persist security info=True;user id=user;password=password;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

This connection string is the same as the conenction string from a different (and working!) .edmx in my solution.


using (var ObjectContext = new TestEntities())
    return ObjectContext.AccountingType.ToList();

TestEntities is DbContext. Any attempt to access ObjectContext.AccountingType, or any other DbSet<> results in the error.

Things I have checked:

  • The Connection String (Model First - See above)
  • Entities mapped correctly? yes
  • Mulitple instances or generations of entity types - no
  • Is the Entities inheriting from a base classes causing the error? no, I removed the base class and made the .tt file generate the INotifyPropertyChanged implementation in the entities directly. Error persists!
  • View the Model/Entity Diagram (*.edmx). Right click the offending Table, and Validate.
  • Read every similar SO question for ideas
  • Replicate the project in a test solution: it works in a separate solution!
  • Move the test project into working solution: same error!

Can anyone think of anything else to try/check??


6/9/2015 7:31:11 PM

Popular Answer

I am also new to EF, and .NET, but i think that by default EF will search for a connection string with the same name as the context's class name, so, may be, if you change the connection string name to "TestEntities", it might do the trick.

5/5/2017 7:44:32 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow