为什么每当我打电话
db.SaveChanges();
我 git 这个错误
The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects
调试后我注意到当我getX()
在模型中调用函数时会出现问题:
public ICollection<Dish> getX()
{
if (this.x== null)
{
return x= this.initX().ToList<X>();
}
return x;
}
而这initX
是一个简单的linq
查询
为什么我不能设置 x 的值?所以当我将线路更改为
return this.initX().ToList<X>(); // whithout x=...
它工作正常...