【发布时间】:2015-10-01 16:01:36
【问题描述】:
我有以下 SQL:
select Monitor.* from Monitor
left join Queue on Queue.MonitorID = Monitor.MonitorID
and Queue.QueueID = (select top 1 Queue.QueueID from Queue where Queue.MonitorID = Monitor.MonitorID order by Queue.Created)
where Queue.Created is null or Queue.Created < 'DateTimeValue'
如果您能想出更好的方法来获取该信息,该查询将选择队列已过期或丢失的所有“监视器”。
此查询的结果是需要运行的过期项目。我正在使用 EF6。
我正在尝试将其从 SQL 转换为 Linq Lambda,我尝试了 Linqer,但它似乎没有输出 Lambda 示例,或者我找不到实现它的设置。
那么,有人可以帮助指导我转换此查询并提供改进(如果有的话)吗?我知道子查询是性能杀手...
一旦我看到它完成了,一旦我觉得我将能够学习语法。
我专门在 linq/lambdas 中寻找这种连接语法的示例
【问题讨论】:
-
我很好奇,看到您有一个有效的查询,为什么不直接查询数据库,而不是使用 LINQ?
-
我很困惑,因为您的原始查询看起来错误。 JOIN 不应该在
Queue.MonitorID=Monitor.MonitorID上吗? -
修复原始查询拼写错误,谢谢!
-
@user2366842 只是想学习其他方法
标签: c# sql-server linq lambda