c# - In Entity Framework, DbContext Remove doesn't remove the object, it kills the relation only -
i new entity framework , doing big project entity framework. realized remove
function doesn't delete object db. nulls relation key.
private void simplebutton2_click(object sender, eventargs e) { try { dialogresult dialogresult = messagebox.show("silmek istediğinize emin misiniz?", "dikkat", messageboxbuttons.yesno); if (dialogresult == dialogresult.yes) { // delete master.hammadekullanilandetail.remove(master.hammadekullanilandetail.last()); mainform.db.savechanges(); gc.datasource = null; gc.datasource = master.hammadekullanilandetail; } } catch { } }
after command executes, database looks this. nulls masterid
how can delete row?
your mainform.db.savechanges()
method wrong. replace with:
master.savechanges()
if master context.
your method should this:
contextname.objectentitiesname.remove(object); contextname.savechanges();
p.s... catch method doesn't anything, should @ least throw;
Comments
Post a Comment