次の方法で共有


LINQ による大量の結果セットのページング

 

公開日: 2016年11月

対象: Dynamics CRM 2015

Microsoft Dynamics CRM 2015 および Microsoft Dynamics CRM Online 2015 更新プログラム では、大量の .NET 統合言語クエリ (LINQ) クエリの結果を、Take 演算子と Skip 演算子を使用してページングできます。Take 演算子は指定された数の結果を取得し、Skip 演算子は指定された数の結果をスキップします。

LINQ ページングの例

以下の例は、LINQ クエリの結果を TakeSkip 演算子を使用してページングする方法を示します。


int pageSize = 5;

var accountsByPage = (from a in svcContext.AccountSet
                      select new Account
                      {
                       Name = a.Name,
                      });
System.Console.WriteLine("Skip 10 accounts, then Take 5 accounts");
System.Console.WriteLine("======================================");
foreach (var a in accountsByPage.Skip(2 * pageSize).Take(pageSize))
{
 System.Console.WriteLine(a.Name);
}

' Retrieve records with Skip/Take record paging. Setting a page size
' can help you manage your Skip and Take calls, since Skip must be
' passed a multiple of Take's parameter value.
Dim pageSize As Integer = 5

Dim accountsByPage = ( _
    From a In svcContext.CreateQuery(Of Account)() _
    Select New Account With {.Name = a.Name})
Console.WriteLine("Skip 10 accounts, then Take 5 accounts")
Console.WriteLine("======================================")
For Each a In accountsByPage.Skip(2 * pageSize).Take(pageSize)
    Console.WriteLine(a.Name)
Next a
Console.WriteLine()
Console.WriteLine("<End of Listing>")
Console.WriteLine()

関連項目

LINQ (.NET 統合言語クエリ) を使用してクエリを作成する
LINQ クエリの例

© 2017 Microsoft. All rights reserved. 著作権