我有一个LINQ查询来获得所有的PreQualCheck,然后我需要按PreQualChecks降序排序,并从有序的集合中获得第一个
下面是我尝试编写查询的方法:
var preQuals = _positionsRepository.GetAll()
.Include(x => x.LoanApplication.PreQualificationChecks)
.Where(x => x.Id == invoice.Position.Id)
.Select(x => x.LoanApplication.PreQualificationChecks)
.OrderByDescending(x=> x.Id)
.FirstOrDefaultAsync();但是我在.OrderByDescending(x=> x.Id)得到了错误,因为它不能获得Id
我该怎么解决这个问题呢?
发布于 2021-03-19 18:20:10
尝尝这个
var preQuals = _positionsRepository.GetAll()
.Include(x => x.LoanApplication.PreQualificationChecks)
.Where(x => x.Id == invoice.Position.Id)
.Select(x => new {x.Id, PreQualificationChecks=x.LoanApplication.PreQualificationChecks})
.OrderByDescending(x=> x.Id)
.FirstOrDefaultAsync();然后您可以像这样访问preQuals:
preQuals.PreQualificationCheckshttps://stackoverflow.com/questions/66705565
复制相似问题