开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜