【发布时间】:2018-12-19 10:26:31
【问题描述】:
我正在使用带有 DB 优先方法的 EF。我在更新 EDMX 文件时遇到问题。假设我有一个表 InvoiceT 和另一个表 LookupT。现在,在 InvoiceT 中,我有一列 InvoiceType 与 LookupT 具有 FK 关系。现在实体在 InvoiceT 类中创建了一个名为 LookupT 的导航属性。到目前为止,它很好。
现在我添加了另一个名为 InvoiceStatus 的列,并使用 LookupT 添加了 FK。现在实体创建另一个名为 LookupT1 的导航属性。但这里的问题是第一个导航属性 LookupT 没有指向其原始数据,即 InvoiceType。相反,它现在指向 InvoiceStatus 数据。任何人都可以向我解释为什么它会这样,我该怎么办?
public class InvoiceT
{
public int InvoiceId {get;set;}
public int InvoiceStatusLkpId {get;set;}
public int InvoiceTypeLkpId {get;set;}
public virtual LookupT LookupT {get;set;} // Previously pointing to Type. Now to Status.
public virtual LookupT LookupT1 {get;set;} // Pointing to Type
}
public class LookupT
{
public int LookupId {get;set;}
public string LookupValue {get;set}
public virtual ICollection<InvoiceT> InvoiceT {get;set;}
public virtual ICollection<InvoiceT> InvoiceT1 {get;set;}
}
【问题讨论】:
-
你不会从问题的标题中知道,但是这个人问了一个非常相似的问题,答案应该很适合你:stackoverflow.com/questions/53792548/…
-
问题在我的场景中有所不同。在您分享的问题中,我认为这个人正在使用代码优先方法。我使用的是 DB 优先方法,因此,我无法控制 EF 生成的类。此外,我的导航属性正在成功生成关系,但唯一的问题是,它们现在指向不同的属性。
标签: asp.net .net entity-framework edmx edmx-designer