【问题标题】:Find Principal end and Dependent end out of EDM model从 EDM 模型中查找 Principal 端和 Dependent 端
【发布时间】:2022-01-06 13:07:57
【问题描述】:

我需要使用 EDM 模型查找所有外键。我能够使用 Systm.Data.Entity.Core.Metadata 类和方法提取许多有用的信息,但仍然无法从关联或关系中获取 Principal 和 Dependent。
ReferentialConstraint 类具有公共属性 FromRole/ ToRole,其中一个是 Principal,另一个是 Dependent,但我不确定到底是哪个。
ReferentialConstraint 有私有字段 PrincipalEndDependentEnd,他们可能会帮助我,但我不想通过反射访问它们。有没有更好的方法来判断什么是Principal,什么是Dependent?

PS:我在这个EF6 - How to determine principal/dependent sides from a NavigationProperty 问题中看到了解决方案,但没有证据证明它是 100% 正确的。

【问题讨论】:

    标签: c# entity-framework .net-core edmx


    【解决方案1】:

    好的,终于找到源代码here

    internal AssociationEndMember PrincipalEnd
    {
        get { return (AssociationEndMember)FromRole; }
    }
    
    internal AssociationEndMember DependentEnd
    {
        get { return (AssociationEndMember)ToRole; }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-17
      • 2014-07-31
      • 1970-01-01
      • 2016-02-11
      • 2015-06-01
      • 1970-01-01
      • 2015-12-28
      • 1970-01-01
      相关资源
      最近更新 更多