使用EF 6,并给出以下课程:
public class A:
{
public int Id{ get; set; }
public string PropA {get; set;}
public string PorpB {get; set;}
public List<B> Bs {get; set;}
}
public class B:
{
public int Id {get; set;}
public string PropB {get; set;}
public string PorpC {get; set;}
}
我想创建一个A对多个B的关系,问题是在复合主键中有不同的名称:
A类中的财产PropB对应于B类中的PropB,而A类中的PropA必须对应于B类中的PropC.
我try 使用模型构建器,但找不到将A类的名称映射到B类的位置:
modelBuilder.Entity<A>(a=>
{
a.HasKey(a => a.Id);
a.HasMany(a=> a.Bs).WithOne().HasPrincipalKey("PropA", "PropB"); <= Can't find PropA in classB
});
我怎么能做到这一点?
Note:我不能修改数据库,也不能使用ID属性创建关系.