我在應用程序中有以下實體。使用Fluent API映射實體關係 - 實體框架
Student
Parent (This Parent can be Father/Guardian)
Address
他們有以下類定義。
public Class Student
{
public int StudentId {get; set;}
//Addresses
public Address TemporaryAddress {get;set;}
public Address PermanentAddress {get;set;}
//Parent
public Parent Father {get;set;}
public Parent Guardian {get;set;}
}
public class Parent
{
public int ParentId {get;set;}
public string Name {get;set;}
//Addresses
public Address TemporaryAddress {get;set;}
public Address PermanentAddress {get;set;}
}
public class Address
{
public int AddressId {get;set;}
public string Country {get;set;}
public string State {get;set;}
public string Town {get;set;}
public string House# {get;set;}
}
,我想有以下排序
Student
->TemporaryAddress (Address)
->PermanentAddress (Address)
->Father (Parent)
->TemporaryAddress (Address)
->PermanentAddress (Address)
->Guardian (Parent)
->TemporaryAddress (Address)
->PermanentAddress (Address)
換句話說它們之間的關係,
學生有一個TemporaryAddress和一個PermanentAddress。 學生有一個父親和一個監護人(他們都可以是相同的,即監護人也可以是父親) 父(父/監護人)有臨時地址和永久地址。
如何使用實體框架的Fluent API實現此?需要在地址和父實體中添加哪些其他字段以使此關係成爲可能。
謝謝。
谷歌在主題標題,你會得到[答案](https://msdn.microsoft.com/en-us/數據/ hh134698.aspx)... – glautrou