【发布时间】:2019-04-23 16:21:47
【问题描述】:
我有下表:
Indicators(A INT, B INT, C INT, D INT, TimeInsertedLocal DateTime) .
我有映射到此表的 EF Core 映射实体。
我需要将此 SQL 查询转换为 ef core Linq 等效查询。
SELECT A, B, C, D, TimeInsertedLocal
FROM Indicators
WHERE TimeInsertedLocal >=
(
SELECT MAX(I.TimeInsertedLocal)
FROM Indicators AS I
)
这是实体:
public class Indicator
{
public int A { get; set; }
public int B { get; set; }
public int C { get; set; }
public int D { get; set; }
public DateTime TimeInsertedLocal { get; set; }
}
如何编写 LINQ 查询,以便 EF Core 生成相同的查询或更好的查询以达到相同的结果?
【问题讨论】:
-
你的相关实体类在哪里?
-
一条记录怎么能大于
MAX(TimeInsertedLocal)? -
TimeInsertedLocal 是插入行的日期时间。
-
我更新了问题,它现在包括实体类。
标签: c# sql linq entity-framework-core