Updating model in EF Database First project
Asked Answered
B

1

10

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

Basket answered 8/6, 2012 at 14:43 Comment(0)
E
13

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

Evident answered 8/6, 2012 at 15:15 Comment(3)
That was exactly it. What is a T4 template by the way?Basket
It's basically a code generation tool based on a text template. You can open the template ( .tt file ) and have a look.Evident
I've been looking for this explaination for some time. Thanks!Mulkey

© 2022 - 2024 — McMap. All rights reserved.