I have several navigation properties from a ‘Users’ table to a ‘Reports’ table. The navigation properties that are generated are obviously accessed like this:
USER.REPORTs.Where(x => ...)
USER.REPORTs2.Where(x => ...)
USER.REPORTs3.Where(x => ...)
The first one is user createdId, second UserApprovedId etc… basic stuff.
These are extremely difficult to interpret. Its difficult to tell which property you are navigating without accessing the EDMX and checking the navigation property.
Now I know I can create my own End1/End2 navigation properties the properties manager but these are lost if the Model is recreated.
Is there a way around this?
I have not tried this, but here’s an idea: since all the entity types are partial classes why not wrap the navigation property generated by Visual Studio in another property with a convenient name?
In your designer file you’ll have something like this:
You can then create another file in which to wrap the navigation property:
You’ll use the property above throughout your code and since the same logic is used when Visual Studio generates the
.edmxfile the wrapped property won’t change.Even if the wrapped property will change its name you’ll need to adjust the code in a single place.