1

我有这个架构:

在此处输入图像描述

Category实体通过ParentCategoryId字段引用自身。ParentCategoryId字段可以为空。我首先使用数据库。这是为此生成的代码entity

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
4

1 回答 1

0

我有一个 pk=0 的类别,当我选择它作为父级时,我提到了错误。删除此类别后,问题得到解决。

于 2013-04-06T11:03:34.120 回答