What is the best way to multiple records in one go in LINQ?
A:
From the blog post http://solidcoding.blogspot.com/2007/12/sql-in-clause-in-linq.html
using (DataContext dc = new DataContext("connectionstring"))
{
List<string> names = new List<string>();
names.Add("Anderson");
names.Add("Johnson");
List<Person> list = (from p in dc.GetTable<Person>() where names.Contains(p.LastName) select p).ToList();
}
Tim Hoolihan
2009-05-15 18:44:18
The question is to delete records, not select them.
ScottS
2009-05-15 18:50:28
A:
The good old SPROCs.....
You can drag the SPROC to your DBML file and it will generate a rich method in your databasecontext class.
Khurram Aziz
2009-05-15 18:47:12
+6
A:
To delete records with Linq2Sql
CustomerDataContext ctx = new CustomerDataContext("connection string"); Customer cust = ctx.Customers.Where(c => c.Name == "david"); ctx.Customers.DeleteAllOnSubmit(cust); ctx.SubmitChanges();
David Liddle
2009-05-15 18:47:46
This is one of the easiest ways but i would not say is the most efficient. There actually is not any optimization being performed. The generated SQL enumerates all objects that match your query, then manually iterates over them to delete them.See this post - http://stackoverflow.com/questions/869209/bulk-deleting-via-linq
David Liddle
2009-05-15 18:56:03
+1
A:
The following is more for LINQ to Entities, but it may help:
http://stackoverflow.com/questions/869209/bulk-deleting-via-linq
Jagd
2009-05-15 18:51:43