Reputation: 1249
Suppose I add a new object to an EntityCollection:
myThingHolder.Things.Add(myThing);
... then later, using the same ObjectContext, before ever saving to the database, I do:
myObjectContext.Things.DeleteObject(myThing);
I get an exception: "The object cannot be deleted because it was not found in the ObjectStateManager."
Other than doing
myThingHolder.Things.Remove(myThing);
is there another solution? I'd like to be able to independently delete the object--just like I can do if the object has been saved previously.
EDIT
I should note that this problem only occurs when myThingHolder is also new and has not yet been saved to the database.
Upvotes: 1
Views: 185