Tuesday, 15 January 2013

c# - EntityFramework - Cannot Delete Entity using DbSet -



c# - EntityFramework - Cannot Delete Entity using DbSet -

this question has reply here:

the object cannot deleted because not found in objectstatemanager in entity framework 5 3 answers

i trying delete object database using entityframework's dbset. code follows:

var dbobject = findbyid(id); _masterdb.dbtable.remove(dbobject); _masterdb.savechanges();

i next error: "the object cannot deleted because not found in objectstatemanager."

please can tell me doing wrong?

possibly entity not attached same context.

does work:

var dbobject = findbyid(id); _masterdb.dbtable.attach(dbobject); _masterdb.dbtable.remove(dbobject); _masterdb.savechanges();

c# entity-framework dbset

No comments:

Post a Comment