LIMIT (Entity SQL)LIMIT (Entity SQL)

在 ORDER BY 子句中使用 LIMIT 子子句可执行物理分页。Physical paging can be performed by using LIMIT sub-clause in ORDER BY clause. LIMIT 不能脱离 ORDER BY 子句单独使用。LIMIT can not be used separately from ORDER BY clause.

语法Syntax

[ LIMIT n ]  

自变量Arguments

n
将选择的项的数量。The number of items that will be selected.

如果 ORDER BY 子句中存在 LIMIT 表达式子子句,则将根据排序规范对查询排序,并且结果行数将受到 LIMIT 表达式限制。If a LIMIT expression sub-clause is present in an ORDER BY clause, the query will be sorted according to the sort specification and the resulting number of rows will be restricted by the LIMIT expression. 例如,LIMIT 5 将结果集限制为 5 个实例或行。For instance, LIMIT 5 will restrict the result set to 5 instances or rows. LIMIT 的功能与 TOP 相当,区别之处是 LIMIT 要求 ORDER BY 子句存在。LIMIT is functionally equivalent to TOP with the exception that LIMIT requires ORDER BY clause to be present. SKIP 和 LIMIT 可独立与 ORDER BY 子句一起使用。SKIP and LIMIT can be used independently along with ORDER BY clause.

备注

如果 TOP 修饰符和 SKIP 子子句出现在同一个查询表达式中,Entity SQL 查询将被视为无效。An Entity Sql query will be considered invalid if TOP modifier and SKIP sub-clause is present in the same query expression. 应重写查询,将 TOP 表达式更改为 LIMIT 表达式。The query should be rewritten by changing TOP expression to LIMIT expression.

示例Example

下面的 Entity SQL 查询将 LIMIT 和 ORDER BY 运算符结合使用来指定用于 SELECT 语句所返回的对象的排序顺序。The following Entity SQL query uses the ORDER BY operator with LIMIT to specify the sort order used on objects returned in a SELECT statement. 此查询基于 AdventureWorks 销售模型。The query is based on the AdventureWorks Sales Model. 若要编译并运行此查询,请执行下列步骤:To compile and run this query, follow these steps:

  1. 执行 How to: Execute a Query that Returns StructuralType Results中的过程。Follow the procedure in How to: Execute a Query that Returns StructuralType Results.

  2. 将以下查询作为参数传递给 ExecuteStructuralTypeQuery 方法:Pass the following query as an argument to the ExecuteStructuralTypeQuery method:

SELECT VALUE p FROM AdventureWorksEntities.Products AS p 
ORDER BY p.ListPrice LIMIT(@limit)

请参阅See also