SET NOCOUNT ON;
Select @itemCount = count(Items.Name) from Items, Categories
Where Items.CategoryID = Categories.CategoryID
and Category = @Category
Return @itemCount
END
The stored procedure takes one input parameter, @Category, which takes the
category value, and returns the @itemCount that contains the number of items
present in the database for the category.
The equivalent method for the above stored procedure will be as follows:
[Function(Name = "dbo.GetNumberofItemsforCategory")]
public int GetNumberofItemsforCategory([Parameter(DbType =
"NVarChar(50)")] string Category)
{
IExecuteResult result = this.ExecuteMethodCall(this,
(MethodInfo)(MethodInfo.GetCurrentMethod())), category);
return ((int)(result.ReturnValue));
}
The above method has the Function attribute with the name which is same as the
GetNumberofItemsforCategory database stored procedure. This method also
. defines the parameters with the Parameter attribute which has the property Name
that has a parameter name Category assigned to it.
Pages:
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189