i have a query like below and i want to update all elements of sequence. but without using foreach/for
var res = _context.tbl1.Where(/* Conditions here */);
res.//Using a method to performing changes;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you’re asking whether you can do set based updates in linq-to-sql as you can in sql, i’m afraid you can’t. You either have to individually update each l2s object and call
SubmitChanges()when you’re done, or callExecuteCommand()with your sql query.Here’s a thread you might be interested in –
http://social.msdn.microsoft.com/Forums/en-US/linqprojectgeneral/thread/0f014318-5259-43c7-8518-06948cec465e
Edit: Actually, this may be of interest to you –
Updating multiple rows Linq vs SQL
If you have a look there’s a link to here – http://www.aneyfamily.com/terryandann/post/2008/04/Batch-Updates-and-Deletes-with-LINQ-to-SQL.aspx which looks kinda cool. Might have to check it out myself!