ReturnValue));
}
}
By using the method, GetNumberofItemsforCategory inside the DataContext
object, the stored procedure directly gets mapped to the method in the
DataContext class.
Following is the code to access and execute the stored procedure. The method is a
strongly typed method which can be accessed directly using the DataContext object,
and the resultant value is returned by the method.
Let us create another stored procedure which will return a result-set. Here, the
result-set is not pre-defined. Let's see how we can define and access the stored
procedure through LINQ to SQL. The text for the stored procedure is as follows:
CREATE PROCEDURE [dbo].[SelectItemDetails](@param nvarchar(50))
AS
SELECT * FROM Items where ([Name] = @param)
Chapter 4
[ 113 ]
This stored procedure, returns all the rows from the Items table for the passed
parameter value which should be the name of the item in the Items table.
The equivalent DataContext class method for the previous stored procedure would
be as follows:
[Function(Name = "dbo.
Pages:
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191