DataServiceQuery<TElement>.AddQueryOption(String, Object) Yöntem

Tanım

Döndürülen sorgu tarafından oluşturulan URI'de ayarlanan sorgu seçeneğiyle yeni DataServiceQuery<TElement> bir oluşturur.

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)

Parametreler

name
String

Eklenecek sorgu dizesi seçeneğinin adını içeren dize değeri.

value
Object

Sorgu dizesi seçeneğinin değerini içeren nesne.

Döndürülenler

Sağlanan sorgunun URI'sine eklenen istenen sorgu seçeneğini içeren yeni bir sorgu.

Örnekler

Aşağıdaki örnekte, yalnızca navlun maliyeti 30 TL'den fazla olan siparişleri döndürmek ve sonuçları azalan düzende sevk tarihine göre sıralamak için sıralı DataServiceQuery<TElement> yöntem çağrılarıyla kullanılan bir AddQueryOption gösterilmektedir.

// 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

Aşağıdaki örnekte, kullanan AddQueryOptionönceki sorguya eşdeğer bir LINQ sorgusu oluşturma işlemi gösterilmektedir.

// 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

Açıklamalar

Sorgu seçenekleri sonuç URI'sine ... kullanılarak ?name=value&name2=value2eklenir. söz dizimi, adın doğrudan parametresiyle name eşlendiği ve value parametresinde value ToString çağrılarak elde edildiği yerdir. ile name$başlar.

WCF Olmayan Veri Hizmetleri söz dizimi ile $başlamaz. WCF Olmayan Veri Hizmetleri sorgu seçenekleri bu yöntem kullanılarak eklenebilir. Seçenek bir WCF Veri Hizmetleri sorgu seçeneği değilse aynı sorgu seçeneğini iki kez eklemek yasaldır. Temel alınan URI'de zaten mevcut olan bir sorgu seçeneği eklenirse, bir özel durum oluşturulur.

Şunlara uygulanır