Could not find the conceptual model type
Asked Answered
A

9

20

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()
Amphithecium answered 23/1, 2012 at 16:26 Comment(3)
Post the code you added, or explain what you did.Lough
The code added was a simple insert into the database using the entity framework and related classes.Amphithecium
Can you mock out the code you added?Lough
A
12

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.

Amphithecium answered 24/1, 2012 at 14:59 Comment(0)
G
9

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

Goodhumored answered 21/1, 2013 at 13:22 Comment(1)
I think it automatically adds the Code Generation Item (.tt file) for you when you go through the Add New Item dialog box and choose the ADO.NET Entity Data Model.Eanore
L
8

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 ;)

Limicolous answered 6/12, 2012 at 9:32 Comment(1)
I installed the Entity Framework 6.0.1 and still have the same problem.Stets
P
8

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.

Parallelize answered 7/2, 2013 at 15:50 Comment(0)
A
2

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...

Aila answered 15/5, 2012 at 19:55 Comment(1)
Yep, POCO and edmx do not mix social.msdn.microsoft.com/Forums/is/adonetefx/thread/…Aphra
E
1

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)

Erminia answered 4/2, 2014 at 21:29 Comment(0)
O
1

I was working with some legacy software and was not keen on upgrading EF. For me, the below setting on my newly added .edmx needed to be changed to match the .edmx that already existed in the project. My new one said "T4" and I changed it to "Legacy Object Context". I did have to delete the .tt templates that were generated previously in order to get it to build. Otherwise, the old generated files stay there and the new files are also there, causing "property already defined" errors. Thx to all the answers above that helped me figure this out!

(Properties panel, after clicking in the entity designer) Code Generation Strategy in Properties

Orthognathous answered 9/12, 2021 at 20:11 Comment(0)
M
0

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.

Marrissa answered 12/11, 2012 at 17:6 Comment(0)
C
0

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

Chain answered 4/1, 2013 at 20:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.