Entity framework ADO.NET实体:从3个表中获取数据

Entity framework ADO.NET实体:从3个表中获取数据,entity-framework,ado.net,Entity Framework,Ado.net,我有以下表格结构: Table: Plant PlantID: Primary Key PlantName: String Table: Party PartyID: Primary Key PartyName: String PlantID: link to Plant table Table: Customer PartyID: Primary Key, link to Party CustomerCode: String 我希望客户实体对象具有以下字段: Party

我有以下表格结构:

Table: Plant
 PlantID: Primary Key
 PlantName: String

Table: Party
 PartyID: Primary Key
 PartyName: String
 PlantID: link to Plant table

Table: Customer
 PartyID: Primary Key, link to Party
 CustomerCode: String 
我希望客户实体对象具有以下字段:

 PartyID: Primary Key
 CustomerCode: String
 PartyName: String
 PlantName: String
PlantName字段(从Plant表中带出)有问题 我通过协会将客户与一方、一方与工厂联系起来 但是,我无法将客户连接到具有关联的工厂(因为它没有关联) 我无法将Plant表添加到映射中,当我这样做时-我遇到以下错误:

Error 3024: Problem in Mapping Fragment starting at line 352: Must specify mapping for all key properties (CustomerSet.PartyID) of the EntitySet CustomerSet
移除植物协会的工作。
非常感谢任何提示或指示。

您可以使用实体对象上的引用路径来获取这些字段

要获取PartyName,请使用以下语法:
Customer.Party.PartyName


要获得PlantName,请使用以下语法:
Customer.Party.Plant.PlantName

经过一些研究,我在MSDN上遇到了这样一个问题,即您可以创建只读实体,这是一个足够的缺点,不能单独使用它,但它会变得更糟。您还将失去根据模式动态更新所有模型的能力f数据库。

您可以使用公共分部类扩展客户实体:

public partial class Customer
{
  public string PartyName
  {
    get { return Party.PartyName; }
    set { Party.PartyName = value; }
  }

  public string PlantName
  {
    get { return Party.Plant.PlantName; }
    set { Party.Plant.PlantName = value; }
  }
}

这是可行的,但字段不是Customer对象的一部分,这是一个缺点,因为我无法在不编写大量代码的情况下将其添加到datagrid(或任何其他数据绑定控件)中。您是否找到解决此问题的方法?我遇到了同样的问题。您的模式中是否有外键?