Database Reference
In-Depth Information
using (var context = new EFRecipesEntities())
{
Console.WriteLine();
Console.WriteLine("Query using LINQ...");
var patients = from p in context.Patients
join ps in context.GetVisitSummary() on p.Name equals
ps.Name
where p.Age >= 40
select ps;
foreach (var patient in patients)
{
Console.WriteLine("{0}, Visits: {1}, Total Bill: {2}",
patient.Name, patient.TotalVisits.ToString(),
patient.TotalCost.ToString("C"));
}
}
}
}
partial class EFRecipesEntities
{
[EdmFunction("EFRecipesModel", "GetVisitSummary")]
public IQueryable<VisitSummary> GetVisitSummary()
{
return this.QueryProvider.CreateQuery<VisitSummary>(
Expression.Call(Expression.Constant(this),
(MethodInfo)MethodInfo.GetCurrentMethod()));
}
}
The code in Listing 11-12 produces the following output:
Query using eSQL...
Robin Rosen, Visits: 2, Total Bill: $1,221.36
Susan Kirby, Visits: 2, Total Bill: $4,036.80
Query using LINQ...
Robin Rosen, Visits: 2, Total Bill: $1,221.36
Susan Kirby, Visits: 2, Total Bill: $4,036.80
How It Works
We started by creating the complex type in the model. With the complex type created, we defined the
GetVisitSummary() function in Listing 11-11 as returning a collection of our newly created complex type. Notice that
the constructor for our complex type takes in parameters in the same order as those defined by our complex type. You
might need to double-check in the .edmx file to make sure that the designer created the complex type properties in
the order in which you created them interactively.
 
Search WWH ::




Custom Search