views:

1485

answers:

3

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.

+3  A: 

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

YeahStu
This works, but the field is not part of Customer object which is a drawback since I can not add it to datagrid (or any other databound controls) without writing a lot of code
+1  A: 

After some research, I came across this thread on MSDN that says you can create a read-only entity, which is enough of a downside to not use it alone, but it gets worse. You will also lose the ability to update all of the models dynamically based on the schema of the database.

ern
+2  A: 

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; }
  }
}
Kris

related questions