LINQ Data Access Layer - Creating Insert Update Delete Stored Procedures

LINQ Data Access Layer - Creating Insert Update Delete Stored Procedures

by David Hayden ( Florida .NET C# SQL Server Developer ), Filed: LINQ To SQL

 

I have been covering LINQ To SQL lately as we develop a fairly large application using LINQ To SQL in the data access layer and Visual Studio 2008. Here are a few of the LINQ To SQL Tutorials to date:

In the last post I discussed creating stored procedures to help select data from the database. In this post I want to briefly describe how to specify Insert, Update, and Delete Stored Procedures in LINQ To SQL to override the dynamic SQL used by the O/R Mapper.

Essentially, you want to create Insert, Update, and Delete Stored Procedures and drag-and-drop them from the Server Explorer in Visual Studio 2008 to the LINQ To SQL Visual Designer surface as I talked about in the previous post. You can then select the appropriate table on the Visual Designer and Right-Click it to Configure Behavior:

 

LINQ Data Access Layer

There are 3 behaviors you can customize: Insert, Update, and Delete. Choose customize and then associate each behavior with the appropriate stored procedure. Method Arguments and Class Properties are typically filled out correctly for you automatically, but if necessary, modify as necessary.

When you are finished, click OK. Now when LINQ To SQL performs an Insert, Update, or Delete, it will use any custom stored procedures as opposed to dynamically generating the SQL. You will see the various methods created in your DataContext Class.

Note this sort of defeats the purpose of using LINQ To SQL, but it may come in handy in special occasions, or if you want to migrate to LINQ To SQL slow and easy.

 

News Feed: David Hayden ( Florida .NET C# SQL Server Developer )

Filed: LINQ To SQL

posted on Wednesday, August 08, 2007 5:01 PM

My Links

Post Categories

Article Categories

Archives

Loose-Leaf Tea