Prev | Current Page 184 | Next

Satheesh, N Kumar

"LINQ Quickly"


IMultipleResults runtimeResultforItems = db.RuntimeShapesforResults(2
);
foreach (Items itm in
runtimeResultforItems.GetResult())
{
Console.WriteLine(itm.Name);
}
IMultipleResults runtimeResultforCategories =
db.RuntimeShapesforResults(1);
foreach (Items itm in
runtimeResultforCategories.GetResult())
{
Console.WriteLine(itm.Name);
}
The result view for the previous code would look like this:
User-Defined Functions
User defined functions are similar to stored procedures. We can map the method
defined on a class to a user-defined function by using the function attribute. The
body of the method constructs the expression and passes it to the DataContext,
which executes the function expression and returns the result.
Chapter 4
[ 117 ]
For example, following is a function that returns the ItemName for the
passed itemID.
CREATE FUNCTION GetItemName(@itemID int)
RETURNS nvarchar(100)
AS
BEGIN
DECLARE @itemName nvarchar(100)
Select @itemName= [Name] from Items where IItemID = @itemID
RETURN @itemName
END
The equivalent method for the DataContext would be as follows:
[Function(Name = "dbo.


Pages:
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
London Escort Agencies Okulary dieta light pensjonaty w beskidach życzenia ślubne