包含投影不起作用

标签 include entity-framework-4.1 projection

我有这个查询

    var test = context.Assignments
        .Include(a => a.Customer)
        .Include(a => a.Subscriptions)
        .Select(a => new AssignmentWithSubscriptionCount { SubscriptionCount = a.Subscriptions.Count(), Assignment = a })
        .ToList();

    var name = test.First().Assignment.Customer.Name;

它无法急切地加载客户,我在 stackoverflow 上看到过类似的问题,而且看起来您不能将投影与包含一起使用。但是我还没有找到解决我的问题的方法..有人吗?

编辑:这是一个热切负载的投影,它比上面的例子更复杂,所以我一生都无法理解出了什么问题,谢谢。
    var test = context.PublicationStateGroups
        .Include(p => p.PublicationStates.Select(ps => ps.AllowedPublicationStateActions.Select(aps => aps.PublicationStateAction)))
        .Select(psg => new StateAndGroupInfo
        {
            ShowReport = psg.PublicationStates.Any(p => p.PublicationStateReportTypeId.HasValue),
            Actions = psg.PublicationStates.SelectMany(state => state.AllowedPublicationStateActions)
                .Select(a => a.PublicationStateAction)
                .Distinct()
        }).ToList();

    var eagerTest = test.First().Actions.First().Name;

最佳答案

这是by design . Include不适用于具有投影或自定义连接的场景。

关于包含投影不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7917348/

相关文章:

c++ - 包括来自不同应用程序/目录的 .h 文件

entity-framework - Entity Framework 复杂类型自定义验证,停止验证递归

opengl - 3D投影映射

Gnuplot:如何在三个坐标面上绘制热图以可视化 4D 数据

C++包含文件浏览器

android - 在android中使用include布局时布局相互重叠

php - 需要多个文件

mapping - Entity Framework 代码优先 - 多对多外键问题

entity-framework-4.1 - Unity 和生命周期管理配置 - 始终 transient 生命周期管理器

graphics - 将 y 剪切地平线偏移转换为光线转换器中的俯仰角