自参考树结构

时间:2019-05-24 15:21:03

标签: c# entity-framework

我将C#与实体框架核心和sql server一起使用。

我想对诸如复合结构之类的东西进行建模,但是在将结构保存到repostiroy中时遇到一些问题。

这是我得到的错误:

  

由于在要保存的数据中检测到循环依赖性,因此无法保存更改:'LogicAnd [已添加] ParentComponent {'ParentComponentId1'} <-条件[Added] <-CompDer {'CompDerId'} LogicAnd [Added]'

基类:

public abstract class Component
{
    public Guid Id { get; set; }

    public int ParentComponentId { get; set; }
    public virtual Component ParentComponent { get; set; }

    public  abstract bool Evaluate();
}

叶类:

public class Condition : Component
{
    public virtual ValueExpression ValueIzq { get; set; }
    public virtual ValueExpression ValueDer { get; set; }
    public String Operation {get;set;}
    public override bool Evaluete(){....}
}

抽象复合类:

public abstract class LogicExpression : Component
{
    public virtual Component CompIzq { get; set; }
    public virtual Component CompDer { get; set; }

}

综合派生类:

public class LogicAnd : LogicExpression
{
    public override bool Evaluete()
    {
           .....
    }
}


public class LogicOr : LogicExpression
{
    public override bool Evaluete()
    {
           .....
    }
}

上下文:

public DbSet<Condition> Conditions { get; set; }
public DbSet<LogicAnd> LogicAnds { get; set; }
public DbSet<LogicOr> LogicOrs { get; set; }


protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<Component>().ToTable("Components");
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    optionsBuilder.UseLazyLoadingProxies();
}

我想念什么?

0 个答案:

没有答案