如何解决使用linq groupby获得最大值
我有一个表ConstructionSets
,下面的数据如图所示,其中前两行的相同initialrevisionId相同,修订版本不同
var constructionSet =_dbContext.ConstructionSets.Include(p => p.AshraeclimateZone)
.Include(p => p.ExteriorWall)
.Where(p.sourceOfDataId == this._designHubProject.EnergyCodeId
&& p.MassingTypeId == this._designHubProject.MassingTypeId)
.GroupBy(p => p.InitialRevisionId)
.Select(g=> g.OrderByDescending(x=> x.Revision).First()).ToList();
并出现如下错误
错误:
The LINQ expression '(GroupByShaperExpression:
KeySelector: (c.InitialRevisionId),ElementSelector:(EntityShaperExpression:
EntityType: ConstructionSet
ValueBufferExpression:
(ProjectionBindingExpression: EmptyProjectionMember)
IsNullable: False
)
)
.OrderByDescending(x => x.Revision)' Could not be translated. Either rewrite the query in a form that can be translated,or switch to client evaluation explicitly by inserting a call to either AsEnumerable(),AsAsyncEnumerable(),ToList(),or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
我正在使用EFCore 3.0
我希望修订的行数更高,并希望从图像中仅获得1st row and 3rd row
之类的两行。
任何人都可以让我知道或提出任何建议为什么我会收到该错误,在此先感谢。
模型类:
public class ConstructionSet
{
[ForeignKey("SourceOfData"),GraphQLIgnore]
public Guid? SourceOfDataId { get; set; }
public virtual CodeStandardGuideline SourceOfData { get; set; }
[ForeignKey("AshraeclimateZone"),GraphQLIgnore]
public Guid? AshraeclimateZoneId { get; set; }
public virtual AshraeclimateZone AshraeclimateZone { get; set; }
[ForeignKey("ExteriorWall"),GraphQLIgnore]
public Guid? ExteriorWallId { get; set; }
public virtual OpaqueConstruction ExteriorWall { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public Guid Id { get; set; }
public MasterSection MasterSection { get; set; }
public Guid? InitialRevisionId { get; set; }
public Guid? LatestRevisionId { get; set; }
[ForeignKey("MassingType"),GraphQLIgnore]
public Guid? MassingTypeId { get; set; }
public MassingType MassingType { get; set; }
public int? Revision { get; set; }
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。