c# - How to delete in linq? -


i select 1 id db , want delete row id:

var ado = new mydbentities(); var selitem = listview3.selecteditems[0];  if (selitem != null) {     var selid = (from t in ado.task                  t.t_name == selitem.text                  select new { t.id});      ado.task.deleteonsubmit(selid);   //this command return error } 

i trying delete deleteonsubmit, error. how can delete row db ?

edit: since seem working objectset, you'll need use deleteobject();

var sel = (from t in ado.task            t.t_name == selitem.text            select t).firstordefault();  if(sel != null)     ado.task.deleteobject(sel); 

deleteonsubmit() takes entity parameter, not anonymous type. should work better;

var sel = (from t in ado.task            t.t_name == selitem.text            select t).firstordefault();  if(sel != null)     ado.task.deleteonsubmit(sel); 

if want delete multiple entities, use deleteallonsubmit() takes enumerable of entities;

var sel = t in ado.task           t.t_name == selitem.text           select t;  ado.task.deleteallonsubmit(sel); 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -