4
在这种关联关系我得到的错误“无法确定类型‘富’和‘酒吧’之间的关联的主要终点的主要结束。该协会的主要终点必须是使用关系流畅API或数据注释显式配置“。无法确定关联
public class Foo
{
public int Id { get; set; }
public int? MainBarId { get; set; }
public virtual Bar MainBar { get; set; }
[InverseProperty("Foo")]
public virtual ICollection<Bar> Bars { get; set; }
}
public class Bar
{
public int Id { get; set; }
public int FooId { get; set; }
public virtual Foo Foo { get; set; }
public int? OldFooId { get; set; }
public virtual Foo OldFoo { get; set; }
}
这里美孚有酒吧的集合,可以有一个主要酒吧(MainBar)。酒吧总是与Foo相关联,但可以引用另一个Foo(OldFoo)。
- 如何使用数据注释在EF中映射它?
- 如果Data Annotations不可行,如何用流利做到这一点?