将多个表FK映射到单个表

时间:2016-08-10 13:32:10

标签: c# asp.net entity-framework

我想要与单个表(地址)形成关系的两个实体(学生和位置)。以下是示例模式:

学生

public int Id { get; set; }
(more student specific properties)
public int PrimaryAddressId { get; set; }
public Address PrimaryAddress { get; set; }
public int SecondaryAddressId { get; set; }
public Address SecondaryAddress { get; set; }

位置

public int Id { get; set; }
(more location specific properties)
public int PrimaryAddressId { get; set; }
public Address PrimaryAddress { get; set; }
public int MailingAddressId { get; set; }
public Address MailingAddress { get; set; }
public int ShippingAddressId { get; set; }
public Address ShippingAddress { get; set; }

地址

public int Id { get; set; }
public string AddressLine1 { get; set; }
...

示例流畅配置

HasRequired(x => x.PrimaryAddress).WithMany().HasForeignKey(x => x.PrimaryAddressId)

我使用Entity Framework 6和流畅的API进行配置。在尝试获取数据时,我获得了经典的“鉴别器”。错误。有人能告诉我建立这种关系的正确方法吗?

谢谢!

0 个答案:

没有答案