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
Post a Comment