【问题标题】:Can you include more than just one relationship level using lambdas in linq to entities您能否在 linq to entity 中使用 lambdas 包含多个关系级别
【发布时间】:2014-06-25 19:10:06
【问题描述】:

我有一个数据结构,其中用户有用户计划,用户计划有计划。我已经包含了 System.Data.Entity 的 using 语句,以便我可以强输入我的包含,但我不知道是否有一种方法可以强输入在关系中超过一个层次的包含。所以我有:

from user in entities.Users.Include(u => u.UserPlans).Include("UserPlans.Plans")

但我希望能够执行以下操作:

from user in entities.Users.Include(u => u.UserPlans).Include(u => u.UserPlans.Include(up => up.Plan))

为了不在我的包含中包含字符串。有办法吗?

【问题讨论】:

    标签: linq linq-to-entities


    【解决方案1】:

    之前好像有人回答过这个问题:EF CTP5 - Strongly-Typed Eager Loading - How to Include Nested Navigational Properties?

    基本上:

    from user in entities.Users.Include(u => u.UserPlans.Select(p => p.Plans))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多