【问题标题】:Need a linq to generate itself join需要一个 linq 来生成自己加入
【发布时间】:2012-09-16 18:59:45
【问题描述】:

根据这篇文章 Why does MYSQL higher LIMIT offset slow the query down? 和这篇文章 http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/ 我需要一个 linq 来创建下面的查询

SELECT  news.*
FROM    (
        SELECT  id
        FROM    news
        WHERE   cat_id= x
        ORDER BY
                id DESC
        LIMIT m, n
        ) o
JOIN    news
ON      news.id = o.id

【问题讨论】:

标签: linq join


【解决方案1】:

应该这样做。 (Skip/Take 等于极限)

from u in news
join n in
(
    from x in news
    where x.cat_id = 10
    orderby x.Id descending
    select x
).Skip(10).Take(20) on u.Id equals n.Id
select u

【讨论】:

  • 此 linq 不会生成我的查询。它的结果也与我的查询不同
  • 只能针对 SQL Server 2008 进行测试,它会生成正确的代码。那么它与您的提供商产生了什么?
  • 以下查询在 MySQL 中生成:SELECT Extent1.Id, ... FROM news AS Extent1 INNER JOIN (SELECT Extent2.Id, ... FROM news AS Extent2 ORDER BY Extent2.Id DESC LIMIT 10,20) AS Limit1 ON Extent1.Id = Limit1.Id
  • 这与您想要的有什么不同? cat_id?只需将其添加到内部查询中
  • @GhootiFarangi 请更具体一些。
猜你喜欢
  • 2019-09-05
  • 2014-03-17
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-25
  • 2021-10-20
相关资源
最近更新 更多