2013-04-05 79 views
1

我有这样的架构时,确定一个有效的排序错误:无法使用自参考

enter image description here

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 
+0

[在实体框架循环依赖条件(http://stackoverflow.com/questions/4304298/circular-dependency-in-entity-framework) – 2013-04-05 11:21:24

+0

使FK为空的,你是好去 – 2013-04-05 11:24:33

+0

ParentCategoryId为空! – 2013-04-05 12:32:17

回答

0

我有PK = 0的类别,当我选择它作为家长我被提到error.after这一类的问题得到解决消除。