Why when ever i call
db.SaveChanges();
i git this error
The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects
after debugging i noticed that the issue occurs when i call getX()
function inside my model :
public ICollection<Dish> getX()
{
if (this.x== null)
{
return x= this.initX().ToList<X>();
}
return x;
}
while the initX
is a simple linq
query
why i cant set the value of x? so when i change the line to
return this.initX().ToList<X>(); // whithout x=...
it works fine ...