0

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 ...

4

1 に答える 1

0

ObjectContextこのトランザクションのすべてのクエリに対して同じインスタンスを使用していることを確認してください。

于 2012-12-05T13:43:36.727 に答える