c# - 为什么 MAX 不能在 Entity Framework 中使用?
问题描述
我是 EF 的新手,写这个是为了选择包含该组合的最大记录。现在我只想挑选MAX
那些记录。
public string GetMaxReportNo(string OfficeStationCombination = "")
{
InspectionReport InspectionReport= new InspectionReport();
string VelosiReportNo="";
var query = uow.InspectionReportRepository.GetQueryable().AsQueryable();
if (!string.IsNullOrEmpty(OfficeStationCombination))
{
VelosiReportNo = (string)query
.Where(x => x.VelosiReportNo.Contains(OfficeStationCombination))
.FirstOrDefault().VelosiReportNo.ToString();
}
return VelosiReportNo;
}
我尝试了一切来选择最大的InspectionReportID记录,where
但没有任何效果
解决方案
按指定列 ( inspectionReportID
)降序排列,然后取第一条记录:
VelosiReportNo = (string)query
.Where(x => x.VelosiReportNo.Contains(OfficeStationCombination))
.OrderByDesc(x => x.inspectionReportID)
.FirstOrDefault().VelosiReportNo.ToString();
推荐阅读
- reactjs - 正在注册未知的服务人员
- python - 循环浏览目录中的文件时如何出现此错误?“OSError:[Errno 2] 没有这样的文件或目录”
- javascript - 在 d3.js 中分离节点并避免在树图中重叠
- function - 获取 Z shell 函数中的函数名
- c# - 执行的序列 ActionFilter 属性是什么?
- kaitai-struct - Kaitai 结构参数类型
- pytorch - 错误 403:尝试在 Google colab 中加载预训练模型时被禁止
- r - 列表与数据框
- python-3.x - 在另一列的基础上将 Count 列增加 1
- html - 如何将包裹在弹性容器中的表单居中?