Could not find the conceptual model type - asp.net-mvc-3

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

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.

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)
Right click on the model’s designer surface.
From the context menu, choose Add Code Generation Item.
In the Add New Item dialog that opens, select Data from the list of installed templates types on the left.
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.

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)

Related

Add CoreData Model shows "Deprecated Feature: Transient Inverse" warning

Using Xcode 10 (iOS project), I'm updating my CoreData model based on the current Model we have and I'm getting the following warning:
"Deprecated Feature"
Transient Inverse feature requires macOS deployment target 10.4 or earlier
(the warning is on the new Model I just created)
The project compiles and runs and is an iOS project not a macOS project. At this point i've literally just created the new model not added any new entities or attributes to it.
Any pointers would be much appreciated
Check all the relationships you have.
Uncheck the option transient.
Then the message disappears.
This warning appears when one or more relationships in your Core Data model have 'Transient' property checked.
In my case this was the way to fix the problem:
Click on your warning in Issue Navigator
Xcode will guide you to your "problematic" relationship
Check properties of the relationship in Data Model Inspector (see picture above)
If everything seems ok with that relationship check the inverse part (entity that relationship is referring to)

What's the best alternative to DropCreateDatabaseIfModelChanges (MVC3)?

I've already checked the other questions and searched in google, but I found a lot of solutions...
What is the best?
I need to Alter the table when the DataModel changes, and I need an automatic Solution (like the DropCreateDatabaseIfModelChanges does..
Thanks a lot for all replies
You can go for CodeFirst Migrations. CodeFirst Migrations. You Need EF 5 binaries.
Run the Enable-Migrations –EnableAutomaticMigrations command in Package Manager Console
Add-Migration will scaffold the next migration based on changes you have made to your model.
Update-Database will apply any pending changes to the database.
To update the Entity Framework EDMX and sync it with your DB changes you double click on the EDMX in the VS2010 Solution Explorer. This brings up the designer (Model Browser window apparently is what it’s called) with a class layout of your entities. Right click anywhere on the designer surface and you’ll see an option in the dialog to “Update Model from Database.” Click on this and you get brought into the Update Wizard where you can choose the database objects you want to Add (if new), but by default it refreshes existing objects.
One thing the wizard doesn’t seem to do is delete columns from existing objects. Probably some sort of safety mechanism, but if you deleted the column from the database, do you really want to keep it in your entity? Ah well, who knows.
It don't works well all the time. In my case I try to create nothing manually with the model editor so each time I modify my database model, I open the EDMX editor, I select all entities and I delete them then, I right click the model and I select option : Update from database.
When the object list appear, I select all table and next. It update the model.

Visual Studio model link not working correctly

First, let me explain what I have done:
I have installed the Visual Studio 2010 Feature Pack both on my local computer and on the TFS host.
The process is documented by Microsoft
I have a VS 2010 modeling solution with a component diagram.
I have created a work item of type Model (custom work item type).
I have created an association from a component in the component diagram, to the Model WI (using Link to Work Item)
The component diagram correctly links to the Model WI
The Model WI correctly contains a model link to the component in the component diagram
Problem: When I click the model link in the Model WI 'All links' tab, I get the following error:
Cannot find the linked model element. The corresponding diagram file or modeling project might have been renamed, moved, or deleted. To fix the link, click the Edit Link button in this work item to re-link the element
I tried to do exactly this, by re-selecting the component using the 'Select model element' dialog. The error is not resolved.
I tried to delete the link and re-create it by creating a new model link. The error is not resolved.
The link looks like this:
ModelLink: modelbus://ComponentDesignerAdapter.1.0/SystemComponentOverview/Architecture::ComponentName/$source control location/filename%comonent-guid
This works perfectly for another modeling project. The error only occurs in this specific modeling project, however it affects more than one component (I do not know if it affects all components in this project)
So my question is this. What could possibly cause this error?
Update: We just realized the error only occurs on my computer. When my colleague attempts to follow the link, the diagram opens correctly. I have tried 'Get latest version' from source control and restarting Visual Studio. Nothing has resolved the issue.
Update 2: I tried creating a new workspace, to no avail. At this point I am concidering re-installing Visual Studio, but I'll hold it off a day or so in case someone knows what might be causing this.

ASP.NET MVC Add View Dialog closing

Recently a large project I work on started having a problem with the Add View dialog. When clicking the Add Strongly-typed View checkbox, the spinner comes up the first time for about a second or two, and then the entire dialog just closes and disappears. If I open the dialog and click the button again, it just closes again quickly.
The project is using ASP.NET MVC 2, I have installed VS2010 SP1 and this problem occurs with or without the MVC3 tools update installed. It only happens with this project, and I have replicated the problem on 2 different development machines. If I create a new MVC2 or MVC3 project, this does not happen at all, nor do any other small to medium sized projects I have.
I can of create a regular view and change it to strongly typed by myself, so there is a workaround, but this is still pretty annoying. Any ideas what could be causing this or how to fix it?
Do you use version control? Make sure all the assemblies that your project depends on (i.e. referenced by the project itself or by its referenced assemblies) are in sync. I've just run into this (both "Add View" and "Add Controller" problems) after updating a bunch of projects from SVN and rebuilding some. The issue was fixed after I rebuilt several libraries that my MVC project depends on.
I had the same problem, and I could not open the Add->Controller dialog either as described here: Add Controller after recent tools update fails with dependency error. In my case, I had added models to my domain, but I had forgotten to add contexts for these new models; things like
public DbSet<Region> Regions { get; set; }
I had no error at compile time, and I was not using these models yes in the solution, so there was no error at run time either. I guess the problem can be anywhere though.

How do I stop the linq designer overwriting my manual changes?

I like Linq but find that once the designer has created my classes I have to modify them.
Then when I change my database and recreate my classes in the designer my changes get wiped.
For instance, let's say I have a class called Person.
I create this class, add some non database related methods to it (outside of Linq) and then create a database table with a similar name.
Linq will duplicate this class in the designer.cs file when I drag it in.
So I go and add the partial keyword to the class in that file or even change the class name Linq created.
As development proceeds, no doubt the database table changes and I have to redrag my tables into the designer.
Voila, my manual changes get wiped.
This is most annoying!
In fact, its unworkable to keep modifying code I have already modified.
Any suggestions?
Create a partial class for your context and make your changes there, the designer generated .cs files are recreated every time you click save.

Resources