LINQ中的删除 [英] Deletion in LINQ
本文介绍了LINQ中的删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有40多个表.第一个表的主键(id)是重置/某些故事的外键.
我想在单个查询中删除子表(包括基表)中与id = 2相关的所有记录.
任何人都可以帮忙.......
谢谢,
Ananth
Hi,
I have more than 40 tables.First table primary key (id) is the foreignkey for reset/some of the tales.
I want to delete all records related to id=2 in sub tables(including base table) in a single query.
can any one help this.......
Thanks,
Ananth
推荐答案
看看 ^ ]很好的文章,可以帮助您入门.
Have a look at this[^] excellent post to start you up.
您是否正在使用LINQ to SQL?
如果是这样,您可以轻松获取要删除的记录的Enumerable,然后在Table上使用RemoveAll方法删除Enumerable中存在的所有记录.
Are you using LINQ to SQL ?
If so, you can easily get the Enumerable of recordes that you want to delete and then use RemoveAll method on the Table to remove all the records present in the Enumerable.
var recordstodelete = from x in emp where emp.jobid = 2 select x;
现在接到此电话后:
now after you get this call:
dbml.Emp.RemoveAll(recordtodelete);
dbml.SubmitChanges();
这就是你所需要的.
:)
this is all u need.
:)
这篇关于LINQ中的删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文