【问题标题】:Difference responses in SQL request and Link request using BLToolkit使用 BLToolkit 的 SQL 请求和链接请求中的差异响应
【发布时间】: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


【解决方案1】:

您可能希望在执行 LINQ 代码后立即检查您的 db.LastQuery。您将看到生成的 SQL,并且可以将其与您真正想要的 SQL 进行比较。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-03
    • 2020-01-23
    • 1970-01-01
    • 2016-06-11
    • 2015-05-21
    • 1970-01-01
    • 2014-12-16
    相关资源
    最近更新 更多