Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating model in EF Database First project

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

like image 833
Sachin Kainth Avatar asked Jun 08 '12 14:06

Sachin Kainth


1 Answers

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

like image 151
Nick Butler Avatar answered Sep 28 '22 11:09

Nick Butler