我们有以下表结构
Person
--ID (PK)
--NAME
Bank Account
P_ID (FK - Person.ID)
Name
Number
RichPerson
P_ID (FK - Person.ID
Age
..other fields
(primary key (P_ID, Age)
我们要努力实现的是为RichPerson加载银行帐户 即
class RichPerson
{
public int P_ID {get;set;}
public int Age {get;set;}
public List<BankAccount> accounts;
}
class Person {
public int ID {get; set;}
public string Name {get;set;}
}
class BankAccount {
public int P_ID {get;set;}
public string Name {get; set;}
public int Number {get;set;}
/* No navigation property is a requirement */
}
我们已经尝试了各种选项,但无法找出可以在这里进行的关联映射,
在我们目前拥有的entitytypeconfigurait中
public class RichPersonMap : EntityTypeConfiguration<RichPerson> {
...
this.HasKey(t => new { t.P_ID, t.Age });
...
this.HasMany(x => x.accounts)
.WithOptional()
.Map(/* WHAT GOES HERE */);
}