Answered by:
Getting the navigational property name for an entity relation.

Question
-
I am trying to build functionality that would allow me to determine whether a lazy-loading POCO collection has been loaded.
What I came up with is getting relationships for an entity through the Relationship Manager and looping through IRelationEnd objects. The problem is there seems to be no easy way to get the entity navigational property name. I played around with debugger and noticed that those objects are actually of type EntityCollection<T> which has a private property NavigationProperty. For now I'm using reflection to get the value and everything works great.
However, this is not something I would ever do in production code. So I'm wondering is there a better way to determine the navigation property name for an entity relationship? I am thinking there is got to be a way to do this by inspecting the SDL but hopefully there is an even easier way. The seem to be many useful properties in the relationship objects that for some reason are private/internal.
Thanks,
DmitryThursday, June 18, 2009 4:45 AM
Answers
-
I'll make sure the relevant folks see this feedback. Not sure if we'll be able to do something in this space for EF4 or not.
- Danny
This posting is provided "AS IS" with no warranties, and confers no rights.- Proposed as answer by simmdanMicrosoft employee Friday, June 19, 2009 11:46 PM
- Marked as answer by Diego B Vega [MSFT]Moderator Sunday, June 21, 2009 6:54 PM
Friday, June 19, 2009 11:46 PM -
Dmitry,
Thanks for the feedback. Making the method public is in a list of things we are considering for this release. I will make sure we also consider the best way to get the navigation property from the related end.
As Danny mentioned, we cannot promise at this point that this will be in EF4.
Thanks,
Diego
This posting is provided "AS IS" with no warranties, and confers no rights.- Marked as answer by Diego B Vega [MSFT]Moderator Sunday, June 21, 2009 6:54 PM
Sunday, June 21, 2009 6:54 PMModerator
All replies
-
Why can't you call the IsLoaded property on the EntityCollection<T>?
This posting is provided "AS IS" with no warranties, and confers no rights.Thursday, June 18, 2009 8:00 PMModerator -
The method takes an entity instance and a navigation property name as a string. In order to get the right EntityCollection<T> I have to get the name of the navigation property from the EntityCollection<T>. If it matches the provided property name, then I do call IsLoaded.
- Edited by Dmitry Starosta Thursday, June 18, 2009 8:40 PM
Thursday, June 18, 2009 8:38 PM -
I have looked into the RelationshipManager class with reflector and there is a very useful method overload.
RelatedEnd GetRelatedEnd(string navigationProperty)
However, it is internal. The public method takes 2 arguments, relationshipName and targetRoleName which is not useful for me. Why could not the overload above be a public method?
Thanks,
DmitryFriday, June 19, 2009 12:42 AM -
I'll make sure the relevant folks see this feedback. Not sure if we'll be able to do something in this space for EF4 or not.
- Danny
This posting is provided "AS IS" with no warranties, and confers no rights.- Proposed as answer by simmdanMicrosoft employee Friday, June 19, 2009 11:46 PM
- Marked as answer by Diego B Vega [MSFT]Moderator Sunday, June 21, 2009 6:54 PM
Friday, June 19, 2009 11:46 PM -
Thanks Danny.
On the related note, it would be very helpful to be able the be able to access the (currently) internal NavigationProperty property on IRelatedEnd/RelatedEnd objects.Saturday, June 20, 2009 6:49 PM -
Dmitry,
Thanks for the feedback. Making the method public is in a list of things we are considering for this release. I will make sure we also consider the best way to get the navigation property from the related end.
As Danny mentioned, we cannot promise at this point that this will be in EF4.
Thanks,
Diego
This posting is provided "AS IS" with no warranties, and confers no rights.- Marked as answer by Diego B Vega [MSFT]Moderator Sunday, June 21, 2009 6:54 PM
Sunday, June 21, 2009 6:54 PMModerator