Found the issue…I had MergeOption.NoTracking set on my context.entity…sigh
Not sure what I’m doing wrong.
The object cannot be deleted because it was not found in the ObjectStateManager.
var deleteOrders = db.TABLE.Where(x => x.WCCR_ID == WccrId && x.ADAM == null).ToList();
foreach (var item in deleteOrders)
{
db.TABLE.DeleteObject(item);
}
db.SaveChanges();
I tried attaching the item db.Attach(item), but that throws an error ‘Object with the same Key already exists’.
thanks for your help. cheers
Your code looks good. Try using:
UPDATE
EF 4.0 uses the
ObjectContextclass.EF 4.1 uses the
DbContextclass in which the methods likeSet<T>andEntryare defined.UPDATE 2
The NuGet package only includes the EF 4.1 runtime and does not include the Visual Studio item templates for using DbContext with Model First and Database First development.
Download: http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=26825