Wondering if anyone else has done most of their Update SQL using stored procedures over Linq2Sql? I like Linq2Sql for all the other operations but Updates seem to be nasty. The generated SQL doesn't look good in profiler with all the columns in the Where clause, then you have to select the current object to set the fields from the edited object before running SubmitChanges(). I'm finding just writing a old fashioned stored procedure better for Updates and using Linq2Sql for the rest. How about your experience?
+4
A:
You don't need all the columns in the Where clause if you include a Timestamp column in your table and a primary key. Then L2S will use those two columns only in the Where clause.
I've built an n-tier data access layer using L2S for a manufacturing operation, without using a single stored procedure. It can be done, and can be done quite well.
Randy
Randy Minder
2010-01-08 21:45:15
Interesting Randy. I'm pretty new to Linq2Sql, inherited a app that used the Codeplex Beerhouse framework. I'll have to look closer at the tables. They have primary keys but will have to check for a timestamp. Something to play around with.
Jason Too Cool Webs
2010-01-08 21:51:35
A:
I had a look at this Update Attach Method from Rick Strahls blog when I was trying to work it out. I ended up just using NHibernate which is, well not easy, but is really nice once you have done a few tutorials. And Update in Nhibernate is easy too. And it supports LINQ if you use Linq to NHibernate
burnt_hand
2010-01-08 21:53:21