我有一个具有TimeSpan属性 ( Start) 和int(Duration以分钟为单位) 属性的实体。
我想执行一个 linq 查询,它将获取适用于以下逻辑的所有行:
Start <= DateTime.Now <= Start + Duration
我的 LINQ
from n in _context.Notifications
where n.Start <= DateTime.Now.TimeOfDay && DateTime.Now.TimeOfDay <= n.Start.Add(new TimeSpan(0, n.Duration, 0))
select n;
Run Code Online (Sandbox Code Playgroud)
转换为(取自 SQL Server Profiler)
SELECT [n].[Id], [n].[Active], [n].[Created], [n].[Day], [n].[Duration], [n].[Name], [n].[Start], [n].[Type]
FROM [Notifications] AS [n]
WHERE [n].[Start] <= CAST(GETDATE() AS time)
Run Code Online (Sandbox Code Playgroud)
我从 EntityFramework Core 收到的警告是
Microsoft.EntityFrameworkCore.Query:Warning: LINQ 表达式 'where (DateTime.Now.TimeOfDay <= [n].Start.Add(new TimeSpan(0, [n].Duration, 0)))' …