代码优先无法确定依赖操作的有效排序

时间:2016-03-24 10:49:52

标签: c# entity-framework

我正在使用EF Code First数据库。这里我有一个实体“Relatie”,它有一个可以为空的父ID(MoederRid)。当我们创建数据库时,我们创建一个默认的Relation,其中Parent本身就是一个业务规则。当我们尝试保存更改时,我们得到:

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

我们一直在搜索谷歌但没有找到答案。任何人都有线索?

类别:

  public partial class Relatie : CreateAT
{
    public Relatie()
    {
        Gebruikers = new HashSet<Gebruiker>();
        Contactpersonen = new HashSet<Contactpersoon>();
        RelatieBestanden = new HashSet<Relatie_Bestand>();
    }

    public int ID { get; set; }

    public int GeslachtEnumID { get; set; }

    public virtual EnumATCode GeslachtEnum { get; set; }

    public string Naam { get; set; }
    public int? MoederRID { get; set; }

    [ForeignKey("MoederRID")]
    public virtual Relatie Moeder { get; set; }
}

添加配置:

private void AddRootRelatie(FrameworkModel context)
    {
        //Add a root relatie. All relations are a member under the root
        var relatie = context.Relaties.SingleOrDefault(m => m.PublicID == FrameworkModel.ROOT_RELATIE_GUID);
        if (relatie == null)
        {
            relatie = new Relatie()
            {
                PublicID = FrameworkModel.ROOT_RELATIE_GUID,
                Naam = "Root",
                GeslachtEnumID = (int)GeslachtEnum.O
            };
            relatie.Moeder = relatie;
            context.Relaties.Add(relatie);
        }
    }

我已经尝试了一些选项:How to insert row in table with foreign key to itself?但不幸的是我没有做到这一点。

0 个答案:

没有答案