DataServiceQuery<TElement>.AddQueryOption(String, Object) 메서드

정의

반환된 쿼리에 의해 생성되는 URI에 설정된 쿼리 옵션을 사용하여 새 DataServiceQuery<TElement>를 만듭니다.

public:
 System::Data::Services::Client::DataServiceQuery<TElement> ^ AddQueryOption(System::String ^ name, System::Object ^ value);
public System.Data.Services.Client.DataServiceQuery<TElement> AddQueryOption (string name, object value);
member this.AddQueryOption : string * obj -> System.Data.Services.Client.DataServiceQuery<'Element>
Public Function AddQueryOption (name As String, value As Object) As DataServiceQuery(Of TElement)

매개 변수

name
String

추가할 쿼리 문자열 옵션의 이름을 포함하는 문자열 값입니다.

value
Object

쿼리 문자열 옵션의 값을 포함하는 개체입니다.

반환

제공된 쿼리의 URI에 추가된 요청된 쿼리 옵션을 포함하는 새 쿼리입니다.

예제

다음 예제에서는 순차 AddQueryOption 적 메서드 호출과 함께 사용되는 를 보여 DataServiceQuery<TElement> 줍니다. 은 화물 비용이 $30를 초과하는 주문만 반환하고 내림차순으로 배송 날짜까지 결과를 주문합니다.

// Create the DataServiceContext using the service URI.
NorthwindEntities context = new NorthwindEntities(svcUri);

// Define a query for orders with a Freight value greater than 30
// and that is ordered by the ship date, descending.
DataServiceQuery<Order> selectedOrders = context.Orders
    .AddQueryOption("$filter", "Freight gt 30")
    .AddQueryOption("$orderby", "OrderID desc");

try
{
    // Enumerate over the results of the query.
    foreach (Order order in selectedOrders)
    {
        Console.WriteLine("Order ID: {0} - Ship Date: {1} - Freight: {2}",
            order.OrderID, order.ShippedDate, order.Freight);
    }
}
catch (DataServiceQueryException ex)
{
    throw new ApplicationException(
        "An error occurred during query execution.", ex);
}
' Create the DataServiceContext using the service URI.
Dim context = New NorthwindEntities(svcUri)

' Define a query for orders with a Freight value greater than 30
' and that is ordered by the ship date, descending.
Dim selectedOrders As DataServiceQuery(Of Order) = context.Orders _
.AddQueryOption("$filter", "Freight gt 30") _
.AddQueryOption("$orderby", "OrderID desc")

Try
    ' Enumerate over the results of the query.
    For Each order As Order In selectedOrders
        Console.WriteLine("Order ID: {0} - Ship Date: {1} - Freight: {2}", _
                order.OrderID, order.ShippedDate, order.Freight)
    Next
Catch ex As DataServiceQueryException
    Throw New ApplicationException( _
            "An error occurred during query execution.", ex)
End Try

다음 예제에서는 를 사용한 AddQueryOption이전 쿼리와 동일한 LINQ 쿼리를 작성하는 방법을 보여줍니다.

// Create the DataServiceContext using the service URI.
NorthwindEntities context = new NorthwindEntities(svcUri);

// Define a query for orders with a Freight value greater than 30
// and that is ordered by the ship date, descending.
var selectedOrders = from o in context.Orders
                     where o.Freight > 30
                     orderby o.ShippedDate descending
                     select o;

try
{
    // Enumerate over the results of the query.
    foreach (Order order in selectedOrders)
    {
        Console.WriteLine("Order ID: {0} - Ship Date: {1} - Freight: {2}",
            order.OrderID, order.ShippedDate, order.Freight);
    }
}
catch (DataServiceQueryException ex)
{
    throw new ApplicationException(
        "An error occurred during query execution.", ex);
}
' Create the DataServiceContext using the service URI.
Dim context = New NorthwindEntities(svcUri)

' Define a query for orders with a Freight value greater than 30
' and that is ordered by the ship date, descending.
Dim selectedOrders = From o In context.Orders _
        Where (o.Freight > 30) _
        Order By o.ShippedDate Descending _
        Select o

Try
    ' Enumerate over the results of the query.
    For Each order As Order In selectedOrders
        Console.WriteLine("Order ID: {0} - Ship Date: {1} - Freight: {2}", _
                order.OrderID, order.ShippedDate, order.Freight)
    Next
Catch ex As DataServiceQueryException
    Throw New ApplicationException( _
            "An error occurred during query execution.", ex)
End Try

설명

쿼리 옵션은 ...를 사용하여 ?name=value&name2=value2결과 URI에 추가됩니다. 이름이 매개 변수에 직접 매핑되고 value 매개 변수에서 name ToString을 호출하여 value 를 가져오는 구문입니다. 는 name$시작합니다.

비 WCF Data Services 구문은 로 $시작되지 않습니다. 이 메서드를 사용하여 비 WCF Data Services 쿼리 옵션을 추가할 수 있습니다. 옵션이 WCF Data Services 쿼리 옵션이 아닌 경우 동일한 쿼리 옵션을 두 번 추가하는 것이 좋습니다. 기본 URI에 이미 있는 쿼리 옵션이 추가되면 예외가 throw됩니다.

적용 대상