EF数据库中的更新模型第一个项目 [英] Updating model in EF Database First project

查看:139
本文介绍了EF数据库中的更新模型第一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个使用实体框架数据库的项目。我正在努力解决如何更新模型类,当我更新数据库,但我无法弄清楚。到目前为止,我已经做了一个名为Test的列添加到数据库中的一个表,然后在Model Browser中,我右键单击了.edmx文件,并从数据库中选择了Update Model,然后跟随出现的向导中的选项。现在,当我查看打开.edmx文件时渲染的数据库关系图,我可以看到测试列已经添加到表中。问题是相应的C#模型类没有更新。我不认为我必须手动更新它,因为该文件顶部有这个消息

  //  - -------------------------------------------------- -------------------------- 
//< auto-generated>
//该代码是从模板生成的。
//
//手动更改此文件可能会导致应用程序出现意外的行为。
//如果重新生成代码,则对该文件的手动更改将被覆盖。
//< / auto-generated>
// -------------------------------------------- ----------------------------------

所以问题是,如何更新这个模型文件?有没有必要运行这样做?



谢谢,



Sachin

解决方案

你应该有一个T4模板(扩展名.tt)来生成你的模型类。



保存.edmx文件可能无法运行,例如,如果它位于不同的项目中。



您可以通过在解决方案资源管理器中右键单击来手动运行它并选择运行自定义工具。


I've inherited a project which uses Entity Framework Database First. I'm trying to work out how to update the model classes when I update the database but I can't figure it out. What I've done so far is added a column called Test to a table in the database, then in Model Browser I've right clicked on the .edmx file and selected Update Model from Database and then followed the options in the wizard that appears. Now, when I look at the database relationship diagram that is rendered when opening the .edmx file I can see that the test column has been added to the table. The problem is that the corresponding C# model class is not updated. I don't think I have to update it manually because the file has this message at the top of it

//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

So the question is, how do I update this model file? Is there something I must run to do this?

Thanks,

Sachin

解决方案

You should have a T4 template ( extension .tt ) that generates your model classes.

It may not run when you save your .edmx file, for example if it is in a different project.

You can run it manually by right-clicking it in solution explorer and choosing "Run Custom Tool".

这篇关于EF数据库中的更新模型第一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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