To map SPROCs to our DataContext class, let's
first go to the VS 2008 Server Explorer window and look at the
SPROCs within our database:
Figure 4
We can double click any of the SPROCs above to open and edit
them. For example, below is the "CustOrderHist" SPROC in
Northwind:
Figure 5
To map the above SPROC to our LINQ to SQL
DataContext, we can drag/drop it from the Server Explorer onto our
LINQ to SQL ORM designer. This will automatically create a new method on
our LINQ to SQL DataContext class like below:
Figure 6
By default the method name created on the
DataContext class will be the same as the SPROC name, and the return type of
the method will be an automatically created type that follows the
"[SprocName]Result" naming pattern. For example: the SPROC above
would return a sequence of "CustOrderHistResult" objects. We
could optionally change the name of the method by selecting it in the designer
and then use the property grid to rename it.