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