EF导航 - 将属性映射到多个表

时间:2016-11-10 20:06:10

标签: sql entity-framework entity-framework-6 mapping

我在表中有一列,它是两个表中任意一个的外键,另一个列是保存哪个表

NoteID    NavigationType    NavigationTypeID
   1        Order               1234
   2        Person              555

我需要将NavigationTypeID映射到Order表或Person表。

public int NoteID { get; set; }
public string NavigationType { get; set; }
public int NavigationTypeID { get; set; }
public virtual Order order{get;set;}
public virtual Person person {get;set;}

我正在使用System.Data.Entity.ModelConfiguration来映射实体

this.HasOptional(t => t.Quote)
.WithOne(t => t.Note)
 .HasForeignKey(d => d.NavigationTypeID);

有没有办法设置我的实体框架映射以根据NavigationType加载此导航?

0 个答案:

没有答案