开发者

ObjectQuery.Include() => ObjectQuery.IncludeAll()

开发者 https://www.devze.com 2023-04-12 09:21 出处:网络
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 automa

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

精彩评论

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

关注公众号