首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ObjectQuery.Include() => ObjectQuery.IncludeAll()

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

Stack Overflow用户
提问于 2011-10-13 02:47:46
回答 1查看 215关注 0票数 2

下面的示例在查询客户时检索一组相关实体。在哪里可以找到递归遍历关系图并自动包含所有关系图的示例?

代码语言:javascript
复制
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");
}

代码语言:javascript
复制
using(Entities context = new Entities())
{
    return context.Customers.IncludeAll().Single(c => c.LastName.StartsWith("Jo");
}
EN

回答 1

Stack Overflow用户

发布于 2011-10-22 16:28:54

这样如何:

代码语言:javascript
复制
context.Customers.Include(c => c.Address.State.Country)
                 .Include(c => c.Phone.PhoneType)
                 .Single(c => c.LastName.StartsWith("Jo");

您不希望包含所有内容,因为并非在所有情况下,您都需要所有内容。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7744964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档