QueryExpression을 사용하여 대형 결과 집합 페이징

 

게시 날짜: 2017년 1월

적용 대상: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

Microsoft Dynamics 365(온라인 및 온-프레미스)에서 페이징 쿠키 기능을 사용하여 큰 데이터 집합에 대해 응용 프로그램에서 빠르게 페이징할 수 있습니다. 이 기능은 FetchXML 및 QueryExpression 쿼리 둘 다에서 사용할 수 있습니다. 레코드 집합을 쿼리할 때 페이징 쿠키 기능을 사용하면 결과에 페이징 쿠키 값이 포함됩니다. 시스템 성능을 향상시키기 위해 다음 레코드 집합을 검색할 때 해당 값을 전달할 수 있습니다.

QueryExpression 및 FetchXML는 해당 페이징 쿠키에 대한 다른 형식을 사용합니다.QueryExpressionToFetchXmlRequest 메시지 또는 FetchXmlToQueryExpressionRequest 메시지를 사용하여 한 쿼리 형식에서 다른 쿼리 형식으로 변환하는 경우 페이징 쿠키 값은 무시됩니다. 또한 비연속된 페이지를 요청하면 페이징 쿠키 값은 무시됩니다.

QueryExpression를 사용하여 페이징 쿠키 사용

다음 예제에서는 쿼리 식을 사용하여 페이징 쿠키를 사용하는 방법을 보여 줍니다. 전체 샘플 코드를 보려면 샘플: 페이징 쿠키와 함께 QueryExpression 사용을 참조하십시오.


// Query using the paging cookie.
// Define the paging attributes.
// The number of records per page to retrieve.
int queryCount = 3;

// Initialize the page number.
int pageNumber = 1;

// Initialize the number of records.
int recordCount = 0;

// Define the condition expression for retrieving records.
ConditionExpression pagecondition = new ConditionExpression();
pagecondition.AttributeName = "parentaccountid";
pagecondition.Operator = ConditionOperator.Equal;
pagecondition.Values.Add(_parentAccountId);

// Define the order expression to retrieve the records.
OrderExpression order = new OrderExpression();
order.AttributeName = "name";
order.OrderType = OrderType.Ascending;

// Create the query expression and add condition.
QueryExpression pagequery = new QueryExpression();
pagequery.EntityName = "account";
pagequery.Criteria.AddCondition(pagecondition);
pagequery.Orders.Add(order);
pagequery.ColumnSet.AddColumns("name", "emailaddress1");                   

// Assign the pageinfo properties to the query expression.
pagequery.PageInfo = new PagingInfo();
pagequery.PageInfo.Count = queryCount;
pagequery.PageInfo.PageNumber = pageNumber;

// The current paging cookie. When retrieving the first page, 
// pagingCookie should be null.
pagequery.PageInfo.PagingCookie = null;
Console.WriteLine("Retrieving sample account records in pages...\n");
Console.WriteLine("#\tAccount Name\t\tEmail Address"); 

while (true)
{
    // Retrieve the page.
    EntityCollection results = _serviceProxy.RetrieveMultiple(pagequery);
    if (results.Entities != null)
    {
        // Retrieve all records from the result set.
        foreach (Account acct in results.Entities)
        {
            Console.WriteLine("{0}.\t{1}\t{2}", ++recordCount, acct.Name,
                               acct.EMailAddress1);
        }
    }

    // Check for more records, if it returns true.
    if (results.MoreRecords)
    {
        Console.WriteLine("\n****************\nPage number {0}\n****************", pagequery.PageInfo.PageNumber);
        Console.WriteLine("#\tAccount Name\t\tEmail Address");

        // Increment the page number to retrieve the next page.
        pagequery.PageInfo.PageNumber++;

        // Set the paging cookie to the paging cookie returned from current results.
        pagequery.PageInfo.PagingCookie = results.PagingCookie;
    }
    else
    {
        // If no more records are in the result nodes, exit the loop.
        break;
    }
}

참고 항목

QueryExpression을 사용하여 쿼리 작성
샘플: 페이징 쿠키와 함께 QueryExpression 사용
샘플: 일대다 관계 검색
QueryExpression 클래스 사용
FetchXML을 사용하여 대형 결과 집합 페이징

Microsoft Dynamics 365

© 2017 Microsoft. All rights reserved. 저작권 정보