Question

I have two Entity Data models within a MVC3 project A and B.

I have recently added the new entity data model B to deal with some new functionality, the issue is that now the existing code has stopped working and I am getting the following error when trying to access code within entity model A.

The error message is:

Could not find the conceptual model type 'project.models.Bclass'

I do not understand why it is this new functionality has affected the current code seeing as entity model A has not change in any way. And functionality B is in a separate class and does not interfere with model A.

When the new code is removed from the project and entity model B is excluded then the code works as it should.

Here is some of the stacktrace from the error:

Exception : Could not find the conceptual model type for 'Project1.Models.CrossSession'.
Application Class - method : System.Data.Metadata.Edm.MetadataWorkspace -- GetEdmSpaceType
User : temp.user
Url : http://localhost/project1/auth/message
Stacktrace :    at System.Data.Metadata.Edm.MetadataWorkspace.GetEdmSpaceType(StructuralType objectSpaceType)
   at System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappings()
   at System.Data.Entity.Internal.InternalContext.TryUpdateEntitySetMappingsForType(Type entityType)
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
Was it helpful?

Solution

Solution found. It appears in some cases (randomly) there is a mix up in the code generated by the entity framework. This is apparently a known bug and a fix should be coming in future releases. In the mean time the way around this is to move the efm to a separate class within the solution.

OTHER TIPS

One possible explanation is that if you use the database first approach and forget to add the Entity classes, you will get this error.

i.e. (from the guide linked below)

  1. Right click on the model’s designer surface.
  2. From the context menu, choose Add Code Generation Item.
  3. In the Add New Item dialog that opens, select Data from the list of installed templates types on the left.
  4. Choose the ADO.NET DbContext Generator then click the Add button.

I normally use Julie Lerman's guide; https://msdn.microsoft.com/en-us/library/jj206878(v=vs.113).aspx

Solved this by updating EntityFramework to the latest version (6.0) http://nuget.org/packages/EntityFramework/.

After installing it regenerate the models and it will work ;)

I had the same problem with 2 different .edmx files in the same project. For the first .edmx model I had used "Add Code Generation Item", for the second model I hadn't. The project was building correctly but throwing that exception on runtime.

I solved generating the .tt classes for the second .edmx model as well.

Well I just installed EF 4.1 and tried to combine DbContext with a EMDX - When I tried to pass back a view I got the same error - that's why I ended up here... I think the way around this is to separate the functionality out into separate asemblies in the solution...

This can also be resolved by generating the new edmx in visual studio 2010 so it matches the older ones... (And copying over the files it generates)

Using Visual Studio 12, the issue has still not been resolved. As an alternative workaround, I set up the second SQL data model using "old fashioned" Data Classes that pre-date entity models - they're still there and they still work. Use Add - New Item - (Data Category) - LINQ To SQL Classes, open the ServerExplorer, locate the server and database, then drag and drop it onto the data classes pane. Old school - but conveniently overcomes this highly inconvenient issue when the full functionality of entity models is not needed.

I removed the edmx models, removed the Entity package, re-install the entity 5.0 and works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top