我将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();
}
我想念什么?