[英]Why MAX is not working with where in Entity Framework?
I am new to EF and writing this to select then max record that contains the combination. 我是EF的新手,正在编写此代码以选择包含组合的max记录。 Now i want to pick MAX
of those records only. 现在,我只想选择这些记录中的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;
}
I tried everything to pick the max InspectionReportID record in where
but nothing works 我尝试了所有操作以选择最大的InspectionReportID记录where
但没有任何效果
Order by the specified column ( inspectionReportID
) descendingly then take the first record: 由指定的列( 订单 inspectionReportID
) 递减然后在第一个记录:
VelosiReportNo = (string)query
.Where(x => x.VelosiReportNo.Contains(OfficeStationCombination))
.OrderByDesc(x => x.inspectionReportID)
.FirstOrDefault().VelosiReportNo.ToString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.