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
Problem:
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:
- new project
- add edmx - include tables model first
- made the entities inherit from a base class that implements INotifyPropertyChanged
- removed the base class and modified the .tt file so the entities implement INotifyPropertyChanged instead
- (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="data source=Stratus;initial catalog=StratusX;persist security info=True;user id=user;password=password;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
This connection string is the same as the conenction string from a different (and working!) .edmx in my solution.
Usage:
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??
thanks
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.