【发布时间】:2022-01-06 13:07:57
【问题描述】:
我需要使用 EDM 模型查找所有外键。我能够使用 Systm.Data.Entity.Core.Metadata 类和方法提取许多有用的信息,但仍然无法从关联或关系中获取 Principal 和 Dependent。ReferentialConstraint 类具有公共属性 FromRole/ ToRole,其中一个是 Principal,另一个是 Dependent,但我不确定到底是哪个。ReferentialConstraint 有私有字段 PrincipalEnd 和 DependentEnd,他们可能会帮助我,但我不想通过反射访问它们。有没有更好的方法来判断什么是Principal,什么是Dependent?
PS:我在这个EF6 - How to determine principal/dependent sides from a NavigationProperty 问题中看到了解决方案,但没有证据证明它是 100% 正确的。
【问题讨论】:
标签: c# entity-framework .net-core edmx