关于Linq 删除多条数据的问题
比如一个新闻模块 我要删除整个模块 那么相关的新闻也要删除 在linq下怎么做 ? 是不是只有用for循环?
linq asp
var q = from c in db.NewsType
where c.NewsType_Id == id
select c;
var w = from c in db.News
where c.News_TypeId == id
select c;
if (q.Count() > 0)
{
for (int e = 0; e < w.Count(); e++)
{
db.News.DeleteOnSubmit(w.First());
db.SubmitChanges();
}
db.NewsType.DeleteOnSubmit(q.First());
db.SubmitChanges();
return true;
}
else
{
return false;
}