【发布时间】:2013-02-18 14:28:46
【问题描述】:
我正在使用 BLToolkit 并发现了一个有趣的行为。我不明白为什么在链接中使用相同的请求会给我不同的结果: SQL 请求:
select TOP 1 * from table where coverCode='1+4'
and effectiveDate <='20130103'
and maxValue >= '1000'
order by maxValue asc, effectivedate desc
这个表实际上有两个结果:
A) (id): 1ffbe215-ff0e-47dd-9718-4130ffb62539 (maxValue): 1000 (effDate):2011-01-01 (价格):40
B) (id): b787a74e-696b-493d-a4bc-5bb407e231b3 (maxValue):1000 (effDate):2011-01-01 (价格):80
SQL 请求给了我 A 结果。 同时请求使用Linq:
db.Rate
.Where(x=>x.coverCode == "1+4"
&& x.effectiveDate <= '20130103'
&& x.MaxValue >= '1000')
.OrderBy(x => x.MaxValue)
.ThenByDescending(x => x.effectiveDate)
这个请求给了我 B 结果。 任何人都可以解释 linq 请求中的原因或问题吗?
【问题讨论】:
-
LINQ 代码无法编译。请向我们展示您执行的实际代码。
-
另外,请发布生成的 SQL,您可以通过运行 SQL Profiler 来捕获它。
标签: linq linq-to-sql bltoolkit