ObjectQuery.Include() => ObjectQuery.IncludeAll()
The following e开发者_运维技巧xample retrieves a set of related entities when customers are queried. Where can I find a sample that recursively walks the relationship graph and includes them all automatically?
using(Entities context = new Entities())
{
return context.Customers
.Include("Address")
.Include("Address.State")
.Include("Address.State.Country")
.Include("Phone")
.Include("Phone.PhoneType").Single(c => c.LastName.StartsWith("Jo");
}
vs.
using(Entities context = new Entities())
{
return context.Customers.IncludeAll().Single(c => c.LastName.StartsWith("Jo");
}
How about this:
context.Customers.Include(c => c.Address.State.Country)
.Include(c => c.Phone.PhoneType)
.Single(c => c.LastName.StartsWith("Jo");
You don't want include all as not in all cases you need everything.
精彩评论