1
我有这样的架构时,确定一个有效的排序错误:无法使用自参考
Category
实体必须通过ParentCategoryId
场到自身的引用。 ParentCategoryId
场是该entity
nullable.I使用数据库第一way.this生成代码:
public partial class Category
{
public Category()
{
this.Category1 = new HashSet<Category>();
this.News = new HashSet<News>();
}
public int CategoryId { get; set; }
public string Name { get; set; }
public Nullable<int> ParentCategoryId { get; set; }
public virtual ICollection<Category> Category1 { get; set; }
public virtual Category Category2 { get; set; }
public virtual ICollection<News> News { get; set; }
}
当我插入一个大类,其ParentCategoryId
字段是空的,每一件事情是确定的,但是当我选择一个值ParentCategoryId
我得到这个异常:
Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values
[在实体框架循环依赖条件(http://stackoverflow.com/questions/4304298/circular-dependency-in-entity-framework) – 2013-04-05 11:21:24
使FK为空的,你是好去 – 2013-04-05 11:24:33
ParentCategoryId为空! – 2013-04-05 12:32:17