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 iade etmek ve sonuçları azalan düzende sevk tarihine göre sıralamak için sıralı AddQueryOption yöntem çağrılarıyla kullanılan bir DataServiceQuery<TElement> 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 örnek, kullanan AddQueryOptionönceki sorguya eşdeğer bir LINQ sorgusunun nasıl oluşturıldığını gösterir.

// 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; burada adı doğrudan parametresiyle name eşler ve value parametresinde value ToString çağrılarak elde edilir. ile name$başlar.

WCF Veri Hizmetleri olmayan söz dizimi ile $başlamaz. bu yöntem kullanılarak WCF Veri Hizmetleri olmayan sorgu seçenekleri 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