Database Reference
In-Depth Information
from EFRecipesEntities.Orders as o
where o.OrderAmount >
anyelement(select value Avg(o.OrderAmount) from
EFRecipesEntities.Orders as o)
group by o.Customer.Name";
var objectContext = (context as IObjectContextAdapter).ObjectContext;
var summary = objectContext.CreateQuery<DbDataRecord>(esql);
foreach (var item in summary)
{
Console.WriteLine("\t{0}, Total Orders: {1}, Total: {2:C}",
item["Name"], item["TotalOrders"], item["TotalPurchases"]);
}
}
}
}
The output of the code in Listing 11-15 is as follows:
Customers with above average total purchases
Bob Meyers, Total Orders: 1, Total: $99.39
Robin Rosen, Total Orders: 1, Total: $101.29
How It Works
In this recipe, we used the canonical functions Count() , Sum() ,and Avg() . These functions are independent of the
data store, which means that they are portable and return types in the EDM space rather than data store-specific or
CLR types.
11-9. Using Canonical Functions in LINQ
Problem
You want to use canonical functions in a LINQ query.
Solution
Let's say that you have a model for movie rentals like the one shown in Figure 11-9 . The MovieRental entity holds the
date that the movie was rented and the date that it was returned, as well as any late fees that have been accumulated.
 
 
Search WWH ::




Custom Search