Renaming navigation property in Entity Framework 5 does not update code

I would like to rename the navigation property and access this object in code using the new name I gave. I renamed one of my user properties to a more meaningful name, rather than 1,2,3 ... etc.

In this example, I renamed OGSMUser5 to OGSMUserResponsible in the model diagram.

Then I tried to access this in the code, but it cannot find my renamed OGSMUserResponsible property.

@contImprovement.OGSMUserResponsible.FullName 

When I look at the code in the model created using the entity data model, I see that the code has not changed for the recently renamed model, which explains why I cannot access it.

  public virtual OGSMUser OGSMUser { get; set; } public virtual OGSMUser OGSMUser1 { get; set; } public virtual OGSMUser OGSMUser2 { get; set; } public virtual OGSMUser OGSMUser3 { get; set; } public virtual OGSMUser OGSMUser4 { get; set; } public virtual OGSMUser OGSMUser5 { get; set; } 

I saw several similar questions, but the answers that I saw, I can’t believe, this is the only option. They manually created a new property with the desired name (what I renamed to the navigation property in the partial class) and return the navigation property with a number in the name to help clear it. I cannot believe that this is the best way to accomplish what I am looking for.

Thanks for the help.

+4
source share
1 answer

You probably did not run T4 template conversions .

Just right click on the .tt files . (they are located under your .edmx file in the Explorer decision tree) and run . Alternatively, you can run all tt by clicking the button on the Visual Studio toolbar.

T4 templates run in Visual Studio

+2
source

Source: https://habr.com/ru/post/1432129/


All Articles