问题
I was attempting to create a new project in VS2012 with an Administrative MVC4 project, Website MVC4 project, and a Common Entity Framework dll project.
I used an existing database an database and generated my entities from it. I updated the names of some of the relation properties and saved. I then added references to the Entity Framework project to both of my MVC4 projects, copied the Entity Framework connection string from App.config fileto each of the Web.config files, and made sure I was referencing the same System.Data.Entity assembly in all 3 projects.
I tried to add an MVC Controller using Entity Framework and received an error. The error stated that my entities did not have properties with certain names. It just so happened the names it was griping about were the ones that I renamed in the Entity Designer. So I ran Clean Solution, rebuilt, and attempted to add the controller again...Same error.
Since it was complaining that it didn't have properties with certain names, I used ILSpy to inspect the assembly that was generated. Sure enough, it did not carry over the names I assigned to the properties in entity designer. Below is a photo of the Designer interface showing that I renamed the classes (yes I saved it), the error message I was getting when attempting to add the MVC controller, and the ILSpy output showing that the properties were not properly renamed in the output assembly.
Is this a bug? Am I doing something wrong?
Update: It seems the .tt files are not automatically firing and regenerating the entities when I make changes to the .edmx design. Not sure what I need to do to get them to run automatically when I save the edmx?
回答1:
There is reported bug which causes this issue when EDMX is not in the root of project directory. When you place EDMX into sub folder you must manually run custom tool to regenerate classes.
回答2:
This was fixed in the VS 2012 Update 1 that was shipped today. You can get it from: http://www.microsoft.com/visualstudio/eng/downloads#d-visual-studio-2012-update
来源:https://stackoverflow.com/questions/12256519/entity-framework-issue-in-vs2012-rename-properties-not-sticking