linq中批量删除用DeleteAllOnSubmit,里面的参数是数据集
传入某要删除的ID列表,使用对象的Contains方法与数据库中值比较,相同就删除。
//批量删除
public void DeleteNews(List<string> IDList)
{
using (ETCDataContext etcDataContext = this.EtcDataContext)
{
var news = etcDataContext.SYS_News.Where(o => IDList.Contains(o.ID.ToString()));
etcDataContext.SYS_News.DeleteAllOnSubmit(news);
etcDataContext.SubmitChanges();
}
}