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?

enter image description here

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

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -