导航属性

时间:2016-03-23 12:17:04

标签: c# entity-framework-6 navigation-properties

如何从导航属性中获取最终属性名称?

在我的模型中,我有一对多的关系如下:

enter image description here

所以,当我拥有Team.Players导航属性时,我想知道,在其关联的另一端,我有一个属性调用Team

所以,为此,首先我得到Team类型,然后我得到它的导航属性。

EntityType myType = irrelevant.GetTypeFromContext('Team');
var TeamNavigationProperties = myType.NavigationProperties;

现在我从Navigation Property开始toEndMember,返回relationship end member

NavigationProperty PlayersNavigationProperty = TeamNavigationProperties[0]; //Simplified code
String endMemberName = PlayersNavigationProperty.toEndMember.Name;  //Which resolves to "Team_Players_Target"

是否可以从Team.Players开始使用Player.Team解决导航结束的问题?

0 个答案:

没有答案