linq - 需要从另一个表中获取最大日期值才能按产品列表排序
问题描述
我有两张桌子。
第一个表是产品表如下:
Product
Id Name
1 Apple
2 Desktop
3 Laptop
ProductStatus
Id ProductId LatestUpdatedDate
1 2 01-01-2021
2 2 08-07-2021
我期待以下结果:
2 Desktop
1 Apple
3 laptop
如何将此查询转换为 linq?
我尝试的样本
var query= _ProductRepository.Table;
var productStatusHistory = (from psh in _productStatusHistoryRepository.Table
group psh by psh.ProductId into g
select g.OrderByDescending(t => t.CreatedOnUtc).FirstOrDefault());
query = (from q in query
join ps in productStatusHistory on q.Id equals ps.ProductId into l_ps
from ps in l_ps.DefaultIfEmpty()
let index = ps == null ? default(DateTime) : ps.CreatedOnUtc
orderby index
select q);
此查询工作正常。我想将此作为单个查询
解决方案
推荐阅读
- asynchronous - 什么是异步,响应式编程必须是异步的吗?
- android - 我无法在 gradle 7.0.0 和 android studio 2020.3.1 中添加 MPAndroidChart
- android - 如何解决“Attribute android: ** not allowed here”错误?
- reactjs - 将认知用户名显示为文本
- python-3.x - 正则表达式第一次出现字符串搜索给出 NULL 输出
- unix - awk 获取一年中所有月份的最后一个工作日
- oracle-sqldeveloper - 为什么 SQL*Developer 代码编辑器运行缓慢?
- c++ - 如何编写具有任意数量参数包的函数
- azure - 不推荐使用 AAD APP 进行身份验证...我的观点是否正确
- python - 如果条件满足,则选择最少两列的更快方法,否则只有一列