VS2012中的实体框架问题 - 重命名属性不粘 [英] Entity Framework Issue in VS2012 - Rename Properties not Sticking

查看:105
本文介绍了VS2012中的实体框架问题 - 重命名属性不粘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在VS2012中创建一个管理MVC4项目,网站MVC4项目和通用实体框架dll项目的新项目。



我使用了一个现有的数据库数据库并从中生成我的实体。我更新了一些关系属性的名称并保存。然后我将Entity Framework项目的引用添加到我的MVC4项目中,将Entity Framework连接字符串从App.config文件复制到每个Web.config文件,并确保我引用了相同的System.Data.Entity程序集所有3个项目。



我尝试使用实体框架添加一个MVC控制器并收到错误。错误表明我的实体没有属性名称。正是这样发生的,就是我在实体设计师中重命名的那些名字。所以我运行了Clean Solution,重建并尝试再次添加控制器...同样的错误。



由于它抱怨说它没有某些名称的属性,我使用ILSpy检查生成的程序集。果然,它没有传递我分配给实体设计师的属性的名字。以下是Designer界面的照片,显示我重命名了类(是的,我保存了它),尝试添加MVC控制器时收到的错误消息,以及显示属性在输出中未正确重命名的ILSpy输出装配。





这是一个bug吗?我做错了吗?






更新:似乎.tt文件不会自动触发并重新生成实体更改.edmx设计。不确定当我保存edmx时,我需要做些什么来让他们自动运行?

解决方案

有一个报告错误,当EDMX不在项目目录的根目录时,会导致此问题。将EDMX放入子文件夹时,必须手动运行自定义工具来重新生成类。


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?

解决方案

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.

这篇关于VS2012中的实体框架问题 - 重命名属性不粘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆