gpt4 book ai didi

linq - NHibernate Linq Group By 无法在 SQL Server 中正确分组

转载 作者:行者123 更新时间:2023-12-03 06:54:46 25 4
gpt4 key购买 nike

我有以下 LINQ 查询,它对 SQL Server 支持的存储库使用 NHibernate...

var casesByCaseOwner = this.preGrantDetailRepository.All
.Where(x => x.CaseFileLocation.Id == cflId)
.GroupBy(x => x.CaseOwner)
.Select(x => new StagSummaryForCfItem
{
Id = x.Key.Id,
Description = x.Key.Name,
NumberOfCases = x.Count(),
UninvoicedNetFee = x.Sum(y => y.UninvoicedNetFee),
UninvoicedDisbursement = x.Sum(y => y.UninvoicedDisbursement)
}).AsEnumerable();

但是,它提示 SQL Server 无法按 CaseOwner.Name 列进行分组,因为它不包含在选择列表或组子句中。来自数据库世界,我理解这个错误,但是,我不确定如何强制 NHibernate 按 IdName 进行分组,但仍然拥有 CaseOwner 实体在我的选择中可用。

最佳答案

终于找到答案了...

     var casesByCaseOwner = this.preGrantDetailRepository.All
.Where(x => x.CaseFileLocation.Id == cflId)
.GroupBy(x => new { x.CaseOwner.Id, x.CaseOwner.Name })
.Select(x => new StagSummaryForCfItem
{
Id = x.Key.Id,
Description = x.Key.Name,
NumberOfCases = x.Count(),
UninvoicedNetFee = x.Sum(y => y.UninvoicedNetFee),
UninvoicedDisbursement = x.Sum(y => y.UninvoicedDisbursement)
}).AsEnumerable();

return casesByCaseOwner;

这很好用,事实证明我需要使用我想要分组的属性来投影一个新实体。

关于linq - NHibernate Linq Group By 无法在 SQL Server 中正确分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9054296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com