<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>LINQ to SQL Extension: Batch Deletion with Lambda Expression</title><link>http://weblogs.asp.net/jeffreyzhao/archive/2008/03/06/linq-to-sql-extension-batch-deletion-by-lambda-expression.aspx</link><description>Batch deletion in the O/R Mapping frameworks is always depressing. If we want to make batch deletion with LINQ to SQL, we'll probably execute a SQL command in souce code. To avoid making batch deletion with SQL commands, I build an extension method for</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>re: LINQ to SQL Extension: Batch Deletion with Lambda Expression</title><link>http://weblogs.asp.net/jeffreyzhao/archive/2008/03/06/linq-to-sql-extension-batch-deletion-by-lambda-expression.aspx#7267422</link><pubDate>Mon, 30 Nov 2009 20:00:48 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7267422</guid><dc:creator>Mitchell</dc:creator><author>Mitchell</author><description>&lt;p&gt;Awesome job - the code is great.&lt;/p&gt;
&lt;p&gt;I tried implementing it for v4.0 and got everything working great except for table mapping - evidently EF 4.0 does not have any properties for accessing for table mappings (due to the fact that multiple database tables can be mapped to a single entity). &amp;nbsp;Any ideas?&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7267422" width="1" height="1"&gt;</description></item><item><title>re: LINQ to SQL Extension: Batch Deletion with Lambda Expression</title><link>http://weblogs.asp.net/jeffreyzhao/archive/2008/03/06/linq-to-sql-extension-batch-deletion-by-lambda-expression.aspx#7258365</link><pubDate>Tue, 17 Nov 2009 23:02:23 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7258365</guid><dc:creator>Terry Aney</dc:creator><author>Terry Aney</author><description>&lt;p&gt;Using the extension from my url above, you could do something like...&lt;/p&gt;
&lt;p&gt;tblMyTables.DeleteBatch( t =&amp;gt; ( new [] { val1, val2, val3, val4 } ).Contains( t.col1 ) );&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7258365" width="1" height="1"&gt;</description></item><item><title>re: LINQ to SQL Extension: Batch Deletion with Lambda Expression</title><link>http://weblogs.asp.net/jeffreyzhao/archive/2008/03/06/linq-to-sql-extension-batch-deletion-by-lambda-expression.aspx#7153571</link><pubDate>Thu, 23 Jul 2009 19:09:33 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7153571</guid><dc:creator>Thrishna</dc:creator><author>Thrishna</author><description>&lt;p&gt;How does this support using a Delete statement with an &amp;quot;IN&amp;quot; clause.&lt;/p&gt;
&lt;p&gt;Like: &amp;quot;DELETE FROM tblMyTable WHERE col1 IN (val1,val2, val3, val4)&amp;quot;&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7153571" width="1" height="1"&gt;</description></item><item><title>re: LINQ to SQL Extension: Batch Deletion with Lambda Expression</title><link>http://weblogs.asp.net/jeffreyzhao/archive/2008/03/06/linq-to-sql-extension-batch-deletion-by-lambda-expression.aspx#6370701</link><pubDate>Mon, 07 Jul 2008 08:06:25 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6370701</guid><dc:creator>Salion</dc:creator><author>Salion</author><description>&lt;p&gt;very good.&lt;/p&gt;
&lt;p&gt;thanks jeffery zhao.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6370701" width="1" height="1"&gt;</description></item><item><title>re: LINQ to SQL Extension: Batch Deletion with Lambda Expression</title><link>http://weblogs.asp.net/jeffreyzhao/archive/2008/03/06/linq-to-sql-extension-batch-deletion-by-lambda-expression.aspx#6096292</link><pubDate>Mon, 14 Apr 2008 08:24:40 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6096292</guid><dc:creator>Terry Aney</dc:creator><author>Terry Aney</author><description>&lt;p&gt;Jeffrey, this article inspired me to create an implementation for both the DELETE and UPDATE. &amp;nbsp;Have a read over at &lt;a rel="nofollow" target="_new" href="http://www.aneyfamily.com/terryandann/post/2008/04/Batch-Updates-and-Deletes-with-LINQ-to-SQL.aspx"&gt;www.aneyfamily.com/.../Batch-Updates-and-Deletes-with-LINQ-to-SQL.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I also made some references to this article and how I understood it. &amp;nbsp;If I misrepresented anything, please let me know.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6096292" width="1" height="1"&gt;</description></item><item><title>re: LINQ to SQL Extension: Batch Deletion with Lambda Expression</title><link>http://weblogs.asp.net/jeffreyzhao/archive/2008/03/06/linq-to-sql-extension-batch-deletion-by-lambda-expression.aspx#6071113</link><pubDate>Sun, 06 Apr 2008 07:32:21 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6071113</guid><dc:creator>Colin B.</dc:creator><author>Colin B.</author><description>&lt;p&gt;Looking at the view from 30,000 feet - Is it only me who thinks that much of Linq is a giant step backward? I mean, comeon, deleting/inserting multiple records is an extremely common task (in my code anyway) and is accomplished using a trivial SQL statement in ADO.NET. This shouldn&amp;#39;t be an exercise in academia!&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6071113" width="1" height="1"&gt;</description></item><item><title>re: LINQ to SQL Extension: Batch Deletion with Lambda Expression</title><link>http://weblogs.asp.net/jeffreyzhao/archive/2008/03/06/linq-to-sql-extension-batch-deletion-by-lambda-expression.aspx#6057244</link><pubDate>Tue, 01 Apr 2008 17:51:23 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6057244</guid><dc:creator>Terry Aney</dc:creator><author>Terry Aney</author><description>&lt;p&gt;If there code available for download at all?&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6057244" width="1" height="1"&gt;</description></item><item><title>扩展LINQ to SQL：使用Lambda Expression批量删除数据。</title><link>http://weblogs.asp.net/jeffreyzhao/archive/2008/03/06/linq-to-sql-extension-batch-deletion-by-lambda-expression.aspx#5924037</link><pubDate>Thu, 06 Mar 2008 03:19:32 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5924037</guid><dc:creator>Zqin</dc:creator><author>Zqin</author><description>&lt;p&gt;扩展LINQ to SQL：使用Lambda Expression批量删除数据。&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5924037" width="1" height="1"&gt;</description></item><item><title>re: LINQ to SQL Extension: Batch Deletion with Lambda Expression</title><link>http://weblogs.asp.net/jeffreyzhao/archive/2008/03/06/linq-to-sql-extension-batch-deletion-by-lambda-expression.aspx#5923825</link><pubDate>Thu, 06 Mar 2008 02:44:08 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5923825</guid><dc:creator>JeffreyZhao</dc:creator><author>JeffreyZhao</author><description>&lt;p&gt;@Richard&lt;/p&gt;
&lt;p&gt;That's an interesting idea.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5923825" width="1" height="1"&gt;</description></item><item><title>re: LINQ to SQL Extension: Batch Deletion with Lambda Expression</title><link>http://weblogs.asp.net/jeffreyzhao/archive/2008/03/06/linq-to-sql-extension-batch-deletion-by-lambda-expression.aspx#5921133</link><pubDate>Wed, 05 Mar 2008 19:18:41 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5921133</guid><dc:creator>Richard</dc:creator><author>Richard</author><description>&lt;p&gt;An alternative approach would be to use the GetCommand method of the DataContext, and alter the command text to delete the matching records. That way, any condition supported by LINQ to SQL is supported.&lt;/p&gt;
&lt;p&gt;The delete command will need to look something like:&lt;/p&gt;
&lt;p&gt;DELETE&lt;/p&gt;
&lt;p&gt;FROM TableName&lt;/p&gt;
&lt;p&gt;FROM TableName As D0 INNER JOIN (SELECT ....) As D1&lt;/p&gt;
&lt;p&gt;ON (D0.Key1 = D1.Key1 And D0.Key2 = D1.Key2 ...)&lt;/p&gt;
&lt;p&gt;where &amp;quot;SELECT ...&amp;quot; is the original command text, and the &amp;quot;ON&amp;quot; clause contains all primary key columns for the table. You can find the primary key columns by using reflection on the entity type:&lt;/p&gt;
&lt;p&gt;from p in entityType.GetProperties()&lt;/p&gt;
&lt;p&gt;from ColumnAttribute a in p.GetCustomAttributes(typeof(ColumnAttribute), false)&lt;/p&gt;
&lt;p&gt;where a.IsPrimaryKey&lt;/p&gt;
&lt;p&gt;select new&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Property = p,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Column = a&lt;/p&gt;
&lt;p&gt;};&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5921133" width="1" height="1"&gt;</description></item></channel></rss>