LINQ series: LINQ to SQL Take/skip

Source: Internet
Author: User

1. Take

var expr = context. Products    . Take (ten);
var expr = ( from in context. Products            select  p)            . Take (ten);
SELECT TOP(Ten)     [C].[ProductID]  as [ProductID],     [C].[CategoryID]  as [CategoryID],     [C].[ProductName]  as [ProductName],     [C].[UnitPrice]  as [UnitPrice],     [C].[UnitsInStock]  as [UnitsInStock],     [C].[discontinued]  as [discontinued]     from [dbo].[Product]  as [C]

2. Skip

  Before you can use the Skip method, you need to sort by order first.

var expr = context. Products    new  {p.productid, p.productname})    = p.productid)    . Skip (ten);
SELECT     [Extent1].[ProductID]  as [ProductID],     [Extent1].[ProductName]  as [ProductName]     from(SELECT [Extent1].[ProductID]  as [ProductID],[Extent1].[ProductName]  as [ProductName], Row_number () Over(ORDER  by [Extent1].[ProductID] ASC) as [Row_number]         from [dbo].[Product]  as [Extent1]    )   as [Extent1]    WHERE [Extent1].[Row_number] > Ten    ORDER  by [Extent1].[ProductID] ASC

3. Paging Query Take/skip

var expr = context. Products    new  {p.productid, p.productname})    = p.productid)    . Skip (ten)    . Take (ten);
SELECT TOP(Ten)     [Extent1].[ProductID]  as [ProductID],     [Extent1].[ProductName]  as [ProductName]     from(SELECT [Extent1].[ProductID]  as [ProductID],[Extent1].[ProductName]  as [ProductName], Row_number () Over(ORDER  by [Extent1].[ProductID] ASC) as [Row_number]         from [dbo].[Product]  as [Extent1]    )   as [Extent1]    WHERE [Extent1].[Row_number] > Ten    ORDER  by [Extent1].[ProductID] ASC

LINQ series: LINQ to SQL Take/skip

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.