【问题标题】:Entity Framework 4 Linq non Lazy Loaded .Include(), include a related entity of a child of the current entityEntity Framework 4 Linq non Lazy Loaded .Include(),包括当前实体的子实体的相关实体
【发布时间】:2011-03-03 06:03:27
【问题描述】:

我有一个实体 A,它与实体 B 在 1:M 关系上相关。 B 以 1:M 关系与 C 相关。

A --> B
B --> C

当我在 A 上包含 B 时,如何包含 C 的集合?

我有这个:

return (from d in _contextProvider.GetContext<SomeContext>().GetObjectQuery<A>().Include("B")
                select d).SingleOrDefault();

我尝试了这个但抛出错误,因为它认为 C 与 A 相关并且找不到关系。

return (from d in _contextProvider.GetContext<SomeContext>().GetObjectQuery<A>   ().Include("B").Include("C")
                select d).SingleOrDefault();

【问题讨论】:

    标签: asp.net entity-framework-4 linq-to-entities


    【解决方案1】:

    试试

    return (from d in _contextProvider.GetContext<SomeContext>().GetObjectQuery<A>().Include("B").Include("B.C") select d).SingleOrDefault();

    【讨论】:

    • 拨打.Include("B.C")时不需要.Include("B"),反正B也会包含在内。
    猜你喜欢
    • 2016-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    • 1970-01-01
    • 2021-04-15
    • 1970-01-01
    • 2014-07-22
    相关资源
    最近更新 更多