我想要优化的代码有两个Linq-to-SQL查询,如下所示:
var maxAInstant =
(
from a in db.As
select a.Instant
)
.Max();
var maxBInstant =
(
from b in db.Bs
select b.instant
)
.Max();
var interval = maxAInstant - maxBInstant;
bool result = interval > new TimeSpan(0, 0, 1);
我可以通过单个Linq-to-SQL查询获得结果吗?
答案 0 :(得分:3)
试试这个:
bool result = (db.As.Max(a => a.Instant) - db.Bs.Max(b => b.instant)) > new TimeSpan(0,0,1);