【发布时间】:2015-04-15 09:20:02
【问题描述】:
我有这门课:
public class Comment
{
public virtual int Id { get; set; }
public string Body { get; set; }
public DateTime AddDate { get; set; }
[ForeignKey("PostId")]
public virtual Post Post { get; set; }
public int PostId { get; set; }
public virtual bool IsApproved { get; set; }
public virtual int LikeCount { get; set; }
public int? ParentId { get; set; }
public virtual Comment Parent { get; set; }
public ICollection<Comment> Children { get; set; }
public virtual Member Member { get; set; }
public virtual byte[] RowVersion { get; set; }
}
我使用这样的 fluent API:
this.HasRequired(x => x.Post)
.WithMany(x => x.Comments)
.WillCascadeOnDelete();
this.HasOptional(x => x.Parent)
.WithMany(x=>x.Children)
.HasForeignKey(x=>x.ParentId)
.WillCascadeOnDelete(false);
当我想运行项目时,我得到了这个错误:
为表“评论”指定了多个标识列。只有一个 允许每个表的标识列。视觉工作室 2013
我在这个类中只有一个主键,即第一行中的Id。
有人吗?我需要帮助
【问题讨论】:
-
你得到的错误在哪里?
-
@Joker 我在帖子中添加了错误。
-
你有流畅的API配置吗?
-
@NikolayKostov 我添加了我的烟道 API。请看。
标签: c# ef-code-first code-first fluent