无法从 IQueryable<十进制,项目 1,模型>转换为 IQueryable<Project 1,模型>



这个错误是什么意思?

我的错误是:

Cannot implicitly convert type 'System.Linq.IQueryable<System.Linq.IGrouping<decimal,Project1.Domain.Models.DepartmentBreakdownReport>>' to 'System.Linq.IQueryable<Project1.Domain.Models.DepartmentBreakdownReport>'. An explicit conversion exists (are you missing a cast?)

想知道它是什么,以便我能够修复它。仅当我将 LINQ GroupBy 添加到结果中时,才会发生这种情况。

 public IQueryable<DepartmentBreakdownReport> GetDepartmentBreakdownBySupplierIDAndReviewID(int ClientID, int? SupplierID, int? ReviewID) {
            return (from d in Db.Details
                    join h in Db.Headers
                    on new { d.ClientID, d.ClaimID }
                    equals new { h.ClientID, h.ClaimID }
                    where d.ClientID == ClientID && h.SupplierID == SupplierID
                    join sd in Db.SuppDepts
                    on new { a = d.ClientID, b = d.CategoryID ?? 0 }
                    equals new { a = sd.ClientID, b = sd.CategoryID }
                    join r in Db.Reviews
                    on new { h.ClientID, h.ReviewID }
                    equals new { r.ClientID, r.ReviewID }
                    join rp in Db.ReviewPeriods
                    on new { a = r.ClientID, b = r.ReviewPeriodID ?? 0 }
                    equals new { a = rp.ClientID, b = rp.ReviewPeriodID }
                    where r.ReviewID == ReviewID
                    join su in Db.Suppliers
                   on new { h.ClientID, h.SupplierID }
               equals new { su.ClientID, su.SupplierID }
                    select new DepartmentBreakdownReport {
                        DepartmentName = sd.DepartmentName,
                        SumOfAmount = d.Amount,
                        SupplierID = h.SupplierID,
                        ReviewID = h.ReviewID,
                        ReviewName = rp.ReviewPeriodName,
                        SupplierName = su.SupplierName,
                        ClientID = d.ClientID
                    }).GroupBy(r=>r.Amount);
        }

此错误是什么意思?

您的返回类型是IQueryable<DepartmentBreakdownReport>,但您正在尝试返回IGrouping<decimal,Project1.Domain.Models.DepartmentBreakdownReport>

当您调用.GroupBy将返回类型更改为 IGrouping 而不是 IQueryable 时,它还引入了小数作为 IGrouping 表达式的一部分(这是您分组依据的金额变量)。

要修复它,您只需将方法签名更改为:

public IGrouping<decimal,Project1.Domain.Models.DepartmentBreakdownReport> GetDepartmentBreakdownBySupplierIDAndReviewID(int ClientID, int? SupplierID, int? ReviewID)
对我来说

,方法名称GetDepartmentBreakdownBySupplierIDAndReviewID意味着:

  • 首先,方法返回类型是这样的,假设 int 的类型为 SupplierIdReviewId

IGrouping<Tuple<int, int>, IQueryable<DepartmentBreakdownReport>> 
                                       GetDepartmentBreakdownBySupplierIDAndReviewID(...)
  • 其次,回报应该在最终预测上,如下所示:

select new DepartmentBreakdownReport { ... })
    .GroupBy(r => new Tuple<int, int>(r.SupplierID, r.ReviewID));

相关内容

  • 没有找到相关文章

最新更新