'Join with max time in EF Core C#
SELECT *
FROM Jobs j
WHERE j.InsertTime = (SELECT MAX(InsertTime) FROM Jobs)
How convert this SQL script to C# query?
I try this but not worked:
from j in _dbContext.Jobs
group j by j.InsertTime into g
select g.OrderByDescending(s=>s.InsertTime).First() into item
select item;
Sample data:
title | insertTime
------|-------------
AA | 2022-05-03
B | 2022-05-03
A | 2022-05-04
B | 2022-05-04
Result:
title | insertTime
------|-------------
A | 2022-05-04
B | 2022-05-04
Solution 1:[1]
Use the following query:
var query =
from d in _dbContext.Jobs.Select(d => new { d.Title }).Distinct()
from j in _dbContext.Jobs
.Wehere(j => j.Ttle == d.Ttle)
.OrderByDescending(j => j.InsertTime)
.Take(1)
select j;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Svyatoslav Danyliv |
