Entity Framework 6 not updating from database correctly in VS 2019 - entity-framework-6

I'm working on a .NET MVC web app using Entity Framework 6 to manage a model from a SQL Server database. I've been using VS 2017 to develop everything so far, making changes to the database, and updating the model after those changes are made. When I switched to VS 2019 and attempted this, only the model and diagram of the model were updated. The classes generated by EF were not updated with the changes from the database. Does VS 2019 handle EF models differently than 2017?

According to this thread on VS Developer Community, it will be fixed in VB2019.1, in the meantime there's a workaround:
Save the .edmx file
Expand the .edmx file in Solution Explorer
For each .tt files inside it, right-click and choose Run Custom Tool.

For what it's worth, I'm experiencing exactly the same issue. The EDMX file gets updated as expected, but additional fields aren't being added to the generated class...
Reopening the project in VS 2017 works, suggesting that something has changed within VS itself.

Related

Where is the option to "Add Project Data Source"?

I have added an SQL data source into my project and I am currently trying to demo an output of the table I have created.
I plan to use a BindingSource control to do so.
However, where there is normally an option to Add Project Data Source, I found nothing (seen in Figure 1), where there should be the option (seen in Figure 2).
I am using Visual Studio 2019, I have tried using .NET 5.0 (current) aswell as Core 3.1 and Core 3.0.
I lost the link where MS says it, but if it helps any I had the same and it turned out this support for databinding is not supported in .Net Core (or at least the version I had). You have to create a windows forms project, then this feature becomes visible.

Pre generated views using entity framework power tool are not working

I am using entity framework with DB first approach. I have migrated from EF5 to EF6 successfully. In EF5, I was using pre generated views to improve startup performance. In EF6, it is not working. I have generated views using power tool. Power tool generated it successfully and I can build the application without any error.
But When I run it, getting following error:
The current model no longer matches the model used to pre-generate the mapping views, as indicated by the ViewsForBaseEntitySetsfc4437b421d2fd7f4d645bf31e3cb5b1b8374d9c77a07ef5f36c1cac0bfea31a.MappingHashValue property.
Pre-generated mapping views must be either regenerated using the current model or removed if mapping views generated at runtime should be used instead
I am not able to understand why there is difference between the hash value generated via power tool and generated by EF at run time. There is no change in the edmx file.
There are more than 290 entities in edmx.
Version of entity framework in 6.1.3.
Power tool is VSPowerTools-Beta4.
I am using visual studio 2013.
Code generation startegy of edmx is 'Legacy ObjectContext'.

Visual Studio 2013 Error ADO.NET Entity Data Model

I am having a problem with Visual Studio 2013.
I start by creating a new project, a ASP.NET Web Application MVC. Then when i try to add a ADO.NET Entity Data Model i get this error:
I had this problem before, but i updated Windows Server, which im using, and Visual Studio too, and it stay good. But now i updated a Sql Server Tools in VS, and this error appears again.
This all happened because i am having a problem, which is, when i try to add a ADO.NET Entity Data Model the wizard closes at the middle of the process. I have searched inumerous posts here on StackOverflow but nothing resolved.
I am using .Net Framework 4.5 and Entity Framework 6
If somebody could help i would be eternally grateful
Ok, the error is gone, i just removed the Update 5 from Visual Studio and it's fine now.
But now there is the other error, when i try to create a ADO.NET Entity Data Model, at the middle of the process, the wizard just closes and the Model it's not created.
Any suggestions?

Entity Framework MVC Controller

I am using Visual Studio 2012. I created a Class project and added EF data model to this project. I created the data model from an existing SQL Server Database. I created a MVC 4 project, added entity connection string to web config, and added data project reference.
All is good to this point.
Now I want to add a MVC controller using Entity Framework. I select a one of the model classes. I select the data context class. Click Add.
VS pops an error up, the last part of the error message is class might be in a compiled assembly {which is true}.
'AA' is not part of the specified 'aanamespace.aaEntity' class and the entity class could not be modified to a DbSet property to it. For example the 'aaEntity' might be in a compiled assembly
I was in the same situation and I created a class library and in it i have all my .edmx and when i have a reference to my mvc project i got the exact the same error message i have posted my question here (stackoverflow.com/questions/18552864/…)
How did I fix:
Close the Visual Studio and open it again...
I want to take the time to answer this question myself so that others with a similar problem can be helped in the future.
Here is what I did.
Created the .edmx file in my Models folder of my MVC project.
Built the MVC project
Now I can add a controller for any of the tables in the .edmx file.
Note:
I thought the best practice was to create a project within my solution that holds the .edmx file. I called this project myData.
I added a reference to this project in my MVC project and tried this scaffolding without luck.
I hope this helps others because the solution is so simple.
Gerry
The problem was caused by the VSCommands for Visual Studio 2012 (Early Access) extension. Once I uninstalled it the problem disappeared.
Run Visual studio (Run as administrator) works for me.
Without seeing the exact error, I can only suggest a problem I experienced with the EF controller scaffolding and how I got around it. If you have extended your EF context class with a partial class, you will have to remove the latter from your project and recompile before generating the controller, otherwise EF scaffolding refuses to work.
Although this is a very old question, but there maybe people like me still facing the same issue which none of the suggested solutions can help them.
The reason for this error message when creating a new controller/scaffolding is the version of your EntityFramework.
HOW TO FIX:
if your project is MVC4 then you should use entity version 5.
if you use Entity version 6 you will face this issue.
remove your .edmx file and add your EntityFramework version 5.
it will work as expected.

Updates to Controllers or Models are not accounted for when recompiling ASP.NET MVC application

This is more of a VS.NET issue I'm sure, but I can't get this to work.
I am updating an older ASP.NET MVC application.
I update code in a class (eg: Controller or Model).
When I rebuild the project/solution and test it (localhost) the changes to the code are not compiled, these changes are not applied. However, changes to the Views take effect immediately.
I am using VS.Net 2010 and app is built in MVC 1.0. Originally the app was built in VS.Net 2008, so when I opened it in VS.Net 2010, the project files were updated. However I did not update the project to a more recent version of .NET.
What am I doing wrong?
This could indeed be some assembly version problem but if you are saying that changes to the views are taken into account it means that the application at least runs correctly. When you opened the project in VS 2010 it probably migrated it to ASP.NET MVC 2.0 (using System.Web.Mvc v2.0.0.0). If you still want to use v1.0 remove the reference of this new assembly and add the older version. Also make sure that there are no binding redirects in web.config. Changes made into controllers and models should be taken into account after recompiling the web application project. Changes to the views are taken into account immediately and no recompilation is needed.

Resources