日期:2014-05-20  浏览次数:20682 次

查询所有的linq对象怎么写???
C# code

 CPJCDataDataContext cc = new CPJCDataDataContext();
 LinkButton lbn = (LinkButton)sender;
        int index = ((GridViewRow)lbn.NamingContainer).RowIndex;
        int id = Convert.ToInt16(GridView1.DataKeys[index].Value);
  City city = cc.City.Where(p => p.Parent_ID == id).FirstOrDefault();
  cc.City.DeleteOnSubmit(city);
        cc.SubmitChanges();
//因为parent_id有很多个,如果我这样写的话,只能删除一个,请问,我该怎么写???



------解决方案--------------------
var citys = cc.City.Where(p => p.Parent_ID == id);
 cc.City.DeleteAllOnSubmit(citys);
 cc.SubmitChanges();