无法确定依赖操作的有效排序? [英] Unable to determine a valid ordering for dependent operations?

查看:509
本文介绍了无法确定依赖操作的有效排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的模型:

public class ContentType
{
    public int ContentTypeId{get;set;}
    public string Name{get;set;}
    public Lang Lang{get;set;}
    public bool IsPublished{get;set;}
    public int? ParentId { get; set; }
    public int UserId { get; set; }
    public virtual User User { get; set; }
    public virtual ContentType Parent { get; set; }
    public virtual List<ContentType> Children { get; set; }
}



它有一个一对多的关系本身。

It has a one to many relation to itself.

和语境中我有这样的:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<ContentType>().HasMany(c => c.Children).WithOptional(c => c.Parent).HasForeignKey(c => c.ParentId);
    base.OnModelCreating(modelBuilder);
    modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();    
}



但是当我保存记录与的ParentId = 0 我看到这个错误:

无法确定相关的操作有效的排序。
依赖可能存在由于外键约束,型号为
的要求,或存储生成的值。

Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values.

请注意在数据库中的关系是不是由于以下错误的存在:

Note that the relation in database is not exist because of the following error:

的ContentType'表
- 无法创建关系 FK_ContentType_ContentType。 ALTER TABLE语句冲突与外键同桌
约束FK_ContentType_ContentType。该冲突发生于
数据库CMS,表dbo.ContentType,列ContentTypeId。

'ContentType' table - Unable to create relationship 'FK_ContentType_ContentType'. The ALTER TABLE statement conflicted with the FOREIGN KEY SAME TABLE constraint "FK_ContentType_ContentType". The conflict occurred in database "CMS", table "dbo.ContentType", column 'ContentTypeId'.

但我别以为这个问题是从这儿过得也不知道。

But I don't think the problem be from here.I don't know.

这是什么错在这里?

推荐答案

看来,这两个错误是由表的ContentType 不正确的数据引起的。

It seems that both errors are caused by the incorrect data in the table ContentType.

的ContentType'表 - 无法创建关系
'FK_ContentType_ContentType。 ALTER TABLE语句冲突
与外键同桌约束
FK_ContentType_ContentType。冲突发生于数据库CMS,
表dbo.ContentType,列ContentTypeId。

'ContentType' table - Unable to create relationship 'FK_ContentType_ContentType'. The ALTER TABLE statement conflicted with the FOREIGN KEY SAME TABLE constraint "FK_ContentType_ContentType". The conflict occurred in database "CMS", table "dbo.ContentType", column 'ContentTypeId'.

这点在的ParentId 字段中的值不正确。确认该字段值实际上正确 ContentTypeId 在其他记录。

This points to the incorrect value in ParentId field. Verify that values in this field are in fact correct ContentTypeId in other records.

无法确定相关的操作有效的排序。
依赖可能存在由于外键约束,型号为
的要求,或存储生成的值。

Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values.

这错误指向一个循环依赖。确认你没有在你的数据周期。

This error points to a circular dependency. Verify that you do not have cycles in your data.

这篇关于无法确定依赖操作的有效排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆