【发布时间】:2014-06-04 09:36:57
【问题描述】:
我有一个对象可以选择引用下一条和/或上一条记录。像这样的:
public class Foo
{
[Key]
public int Id {get; set;}
[ForeignKey("Previous")]
public int? PreviousId {get; set;}
public Foo Previous {get; set;}
[InverseProperty("Previous")]
public Foo Next {get; set;}
}
不幸的是,这不起作用,而是导致错误消息Unable to determine the principal end of an association between the types Foo and Foo。
这个想法是,通过设置PreviousId,前一个Foo 将由EF 自动设置其Next。这是为了防止Next 和Previous 不同步导致的错误。还要注意PreviousId 可以是null,在这种情况下,数据库中的任何记录都不应该有指向该记录的Next。有什么方法可以实现吗?
【问题讨论】:
标签: entity-framework entity-framework-6