【问题标题】:Entity Core: Select Anonymous Type and Count Error : No value provided for required parameter _outer实体核心:选择匿名类型和计数错误:未为所需参数 _outer 提供值
【发布时间】:2017-08-22 16:16:13
【问题描述】:

当我尝试选择并计入匿名类型时,我在使用 Entity Framework Core 1.1 时遇到了一些问题

错误:InvalidOperationException:未提供所需的值 参数“_outer_ProductCategoryID”。

代码:

 rets = context.ProductCategories.Select
                          (
                              y => new ProductCategory
                              {
                                  Title = y.Title,
                                  ProductCategoryID = y.ProductCategoryID,
                                  ProductCount = y.ProductCategoryFiles.Count()

                              }
                          ).ToList();

【问题讨论】:

  • 同样的问题,似乎可能是 ef 核心限制。

标签: parameters entity-framework-core outer-join anonymous


【解决方案1】:

将在 1.1.2 EF 版本中修复。更多内容:https://github.com/aspnet/EntityFramework/issues/7714

解决方法是首先计算普通匿名动态对象,然后投影到您的 DTO:

context.ProductCategories.Select(c => new { Count = c.ProductCategoryFiles.Count() }).ToList().Select(r => new ProductCategoryDTO { Count = r.Count,... });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-03
    • 2017-02-17
    • 1970-01-01
    • 2019-11-26
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    相关资源
    最近更新 更多