为什么 LINQ 日期列比较不起作用?
对于像这样的 LINQ 查询:
var entities = from Account p in context.Accounts
where p.LastTimeServerSettingsChanged > p.LastTimeDeviceConnected
select p;
生成的查询是:
SELECT
[Extent1].[Username] AS [Username],
[Extent1].[LastTimeDeviceConnected] AS [LastTimeDeviceConnected],
[Extent1].[LastTimeServerSettingsChanged] AS [LastTimeServerSettingsChanged]
FROM [dbo].[Account] AS [Extent1]
WHERE [Extent1].[LastTimeServerSettingsChanged] > [Extent1].[LastTimeDeviceConnected]
这不起作用(没有结果)。
下面也生成相同的 SQL(因此也没有结果)
var entities = context.Accounts.Where(k => k.LastTimeServerSettingsChanged > k.LastTimeDeviceConnected).Select(k => k);
我的问题是为什么,以及如何执行此查询(使用 LINQ)?
For a LINQ query like:
var entities = from Account p in context.Accounts
where p.LastTimeServerSettingsChanged > p.LastTimeDeviceConnected
select p;
the query that is generated is:
SELECT
[Extent1].[Username] AS [Username],
[Extent1].[LastTimeDeviceConnected] AS [LastTimeDeviceConnected],
[Extent1].[LastTimeServerSettingsChanged] AS [LastTimeServerSettingsChanged]
FROM [dbo].[Account] AS [Extent1]
WHERE [Extent1].[LastTimeServerSettingsChanged] > [Extent1].[LastTimeDeviceConnected]
And this does not work (no results).
And the following also generates the same SQL (hence no results also)
var entities = context.Accounts.Where(k => k.LastTimeServerSettingsChanged > k.LastTimeDeviceConnected).Select(k => k);
My question is why, and how can this query be performed (using LINQ)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上面的代码工作正常。我访问了错误的数据库,因此得到了错误的结果。吉戈。量子ED。
The above code works fine. I was hitting the wrong database and hence was getting the wrong result. GIGO. QED.