LINQ to SQL: Updating with Stored Procedures

Override the generated ORM update/delete/insert logic with your own through stored procedures. The video also shows in detail how to use the SQL Profiler to monitor the changes in the ORM from generated SQL to our custom SQL stored procs. Since we're just writing SQL, the same techniques apply to both C# and VB developers.

Presented by Scott Stanfield

Duration: 15 minutes, 36 seconds

Date: 13 March 2008

Watch the video   |   Get the code

Video downloads: WMV | Zune | iPod | PSP | MPEG-4 | 3GP

Audio downloads: AAC | WMA | MPEG-4 | MPEG-3 | MPEG-2

Comments : 3

Leave a Comment

chenyaping034 : On March 14, 2008 10:02 AM said:

I like the video!I wish more and more the good video about the konwledge of LINQ

Lee Dumond : On April 08, 2008 1:35 PM said:

Just would like to point out a couple of errors in the code:

In part9.aspx, line 31:

Product p = db.Products.Single(p => p.ProductName == "Foo");

You can't declare a local variable "p" in the lambda expression here, because "p" is already used to denote the Product. You could change it to something else, like:

Product p = db.Products.Single(prod => prod.ProductName == "Foo");

In Helpers.cs, line 57:

return ExecuteCommand("delete from products where ProductId={0}", instance.ProductID);

DeleteProduct is a void method, so it can't return anything.  You need to get rid of the "return" keyword.

LoftenPierce : On April 21, 2008 3:17 PM said:

I have a question:  I want to be able to leverage my code to use LinQ to sql.  We have a DAL generator that creates our sprocs from out tables.  As such, we include the CRUD sql code in the sproc, using an "Action" parameter, which tells which sql code to run (0=read, 1=create, 2=update, and 3=delete).  I've been trying to get linq to work with this model.  How do I get linq to use the parms that I want and ignore the rest? Here's how I get it to work now:

       Dim db As New MOCDataContext

       Dim q = db.SProc_MOCT_CC(0, Nothing, Nothing, Nothing, Nothing, Nothing)

       GridView1.DataSource = q

       GridView1.DataBind()

The first parm is the action, the rest I set to use 'Nothing' to ignore the other parms.  Normally, I would just pass the parms I wanted the 2nd or third parms I would fill in (via class properties) and leave the others.  How can I get around this?  Am I making sense?

Leave a Comment

You must be logged in to leave a comment. Click here to log in.

Featured ASP.NET 3.5 Web Hosting


Featured ASP.NET 3.5 hosting offer from AppliedI.net

Click Here To Learn More...