here is a example of how compiled query is used in LINQ to Entities scenario:
var q = from c in ctx.Customers
where c.CustomerID == "ALFKI"
select new { Customer = c, Orders = c.Orders };
var cq = CompiledQuery.Compile((NorthwindEntities ctx) => q);
foreach(var p in cq(ctx))
{
Console.Write(p.CustomerId);
...
}
A queriable collection has a method Include:
var q = from c in ctx.Customers.Include("Orders")
where c.CustomerID == "ALFKI"
select c;
it can be used to get Customers that has Orders.
No comments:
Post a Comment