Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ADO.NET Entity : getting data from 3 tables

I have following table structure:

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 

I'd like to have Customer entity object with following fields:

 PartyID: Primary Key
 CustomerCode: String
 PartyName: String
 PlantName: String

I am having trouble with PlantName field (which is brought from Plant table I connected Customer to Party and Party to Plant with associations However I can not connect Customer to Plant with association ( because it does not have one) I can not add Plant table to mapping, when I do that - I am getting following error:

Error 3024: Problem in Mapping Fragment starting at line 352: Must specify mapping for all key properties (CustomerSet.PartyID) of the EntitySet CustomerSet

Removing Plant association works. Any hints or directions very appreciated.

like image 945
Michael Feinstein Avatar asked Dec 13 '25 22:12

Michael Feinstein


2 Answers

You can get these fields by using the reference path on the Entity Object.

To get the PartyName, use this syntax: Customer.Party.PartyName

To get the PlantName, use this syntax: Customer.Party.Plant.PlantName

like image 135
YeahStu Avatar answered Dec 16 '25 03:12

YeahStu


You can extend the Customer entity by using the public partial class:

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; }
  }
}
like image 21
Kris Avatar answered Dec 16 '25 03:12

Kris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!