I would like to rename a navigation property and access that object in code by the new name I gave. I have renamed one of my user properties to a more meaningful name rather than 1,2,3…etc.
In this example, I have renamed OGSMUser5 to OGSMUserResponsible in the model diagram.
I then tried to access this in code, but it can’t find my renamed property OGSMUserResponsible.
@contImprovement.OGSMUserResponsible.FullName
When I look at the code in the model generated from Entity Data Model, I see that the code did not change for the newly renamed model, which explains why I can’t 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 have seen somewhat similar questions to this, but the answers I have seen I can’t believe is the only option. They have been manually creating a new property with the name you want (what I renamed mine to in the navigation property) in a partial class and return the navigation property with the number in the name to help clean it up. I can’t believe that this is the best way to accomplish what I am looking for.
Thanks for the help.
You probably didn’t run the T4 template transformations.
Just right click your .tt files (they are under your .edmx file in the Solution Explorer tree) and run them. Alternatively, you can run all tt by clicking the button in Visual Studio’s toolbar.