Using LINQ to SQL - Part 2
page 8 of 11
by Scott Guthrie
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 45284/ 77

Using Stored Procedures

LINQ to SQL allows you to optionally model stored procedures as methods on your DataContext class.  For example, assume we've defined the simple SPROC below to retrieve product information based on a categoryID:

Figure 10

I can use the server explorer within Visual Studio to drag/drop the SPROC onto the LINQ to SQL designer surface in order to add a strongly-typed method that will invoke the SPROC.  If I drop the SPROC on top of the "Product" entity in the designer, the LINQ to SQL designer will declare the SPROC to return an IEnumerable<Product> result:

Figure 11

I can then use either LINQ Query Syntax (which will generate an adhoc SQL query) or alternatively invoke the SPROC method added above to retrieve product entities from the database:

Figure 12


View Entire Article

User Comments

Title: LInq to Sql   
Name: praveen
Date: 2010-11-08 4:24:52 AM
Comment:
hi ...this example was good...your practical approach was good..
Title: sample code   
Name: SirReadALOT
Date: 2010-04-08 6:49:21 PM
Comment:
hi would it be possible to downlad the application?
Title: stored procedure   
Name: pappu reddy
Date: 2009-03-18 6:09:56 AM
Comment:
can u give any other implementation






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-25 3:04:50 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search