工作内容的临时备忘,Linq代码片段。
分组查询取每组中最小的值或最大值
var bridgeCongnizaceAssessSource =await _bridgeCognizanceAssessRepository
.Where(x => x.IsDeleted == 0 && x.TableName == BridgeServiceConstValue.Table_thematic_evaluation)
.GroupBy(d => d.ComeFromId).Select(grp=>new DangerousBridgeCognizanceAssessEntity(){ComeFromId = grp.Key, DangerousBridgeLv = grp.Min(x=>x.DangerousBridgeLv)}).ToListAsync();
var bridgeMainLineIdList = bgeLineInfoRepository.GroupBy(d => d.Bge_Id).Select(grp => grp.Min(x => x.Id))
.ToListAsync();
分组取最小值。
参考资料
https://www.pluralsight.com/guides/grouping-aggregating-data-linq
linq比较两个list是否相等
参考:https://www.techiedelight.com/compare-two-lists-for-equality-csharp/
文档信息
- 本文作者:hillcat
- 本文链接:https://cs-cn.top/2018/04/27/Linq_GroupBy/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)