Updating model in EF Database First project

梦想的初衷 提交于 2019-11-30 03:11:16

问题


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


回答1:


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".



来源:https://stackoverflow.com/questions/10951040/updating-model-in-ef-database-first-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!