【发布时间】:2013-11-07 00:41:24
【问题描述】:
我有这门课:
public class Message
{
public long Id { get; set; }
public string Subject { get; set; }
public string Message { get; set; }
public virtual Message ParentMessage { get; set; }
public virtual Message ChildMessage { get; set; }
//...
}
使用EntityFramework Code First Add-Migration 给我消息:Unable to determine the principal end of an association between the types...
我不能使用[Required] 属性,因为该线程中的第一条消息将没有父消息,线程中的最后一条消息将没有子消息...我该如何映射?
我试过了:
modelBuilder.Entity<Message>()
.HasOptional(x => x.ParentMessage);
modelBuilder.Entity<Message>()
.HasOptional(x => x.ChildMessage);
但这没有用。
【问题讨论】:
-
Serj - 我误读了您的问题并删除了我的帖子。很抱歉提供了不好的信息。
标签: c# entity-framework entity-framework-5 self-reference