Compartilhar via


QueryResult<T> Class

[WCF RIA Services Version 1 Service Pack 2 is compatible with either .NET framework 4 or .NET Framework 4.5, and with either Silverlight 4 or Silverlight 5.]

Message type used to communicate query results between the server and client.

Inheritance Hierarchy

System.Object
  System.ServiceModel.DomainServices.Client.QueryResult
    System.ServiceModel.DomainServices.Client.QueryResult<T>

Namespace:  System.ServiceModel.DomainServices.Client
Assembly:  System.ServiceModel.DomainServices.Client (in System.ServiceModel.DomainServices.Client.dll)

Syntax

'Declaration
<DataContractAttribute(Name := "QueryResultOf{0}", Namespace := "DomainServices")> _
Public NotInheritable Class QueryResult(Of T) _
    Inherits QueryResult
'Usage
Dim instance As QueryResult(Of T)
[DataContractAttribute(Name = "QueryResultOf{0}", Namespace = "DomainServices")]
public sealed class QueryResult<T> : QueryResult
[DataContractAttribute(Name = L"QueryResultOf{0}", Namespace = L"DomainServices")]
generic<typename T>
public ref class QueryResult sealed : public QueryResult
[<SealedAttribute>]
[<DataContractAttribute(Name = "QueryResultOf{0}", Namespace = "DomainServices")>]
type QueryResult<'T> =  
    class
        inherit QueryResult
    end
JScript does not support generic types and methods.

Type Parameters

  • T
    The data type.

The QueryResult<T> type exposes the following members.

Constructors

  Name Description
Public method QueryResult<T>() Initializes a new instance of the QueryResult<T> class with default values.
Public method QueryResult<T>(IEnumerable<T>) Initializes a new instance of the QueryResult<T> class with the specified collection of result items.
Public method QueryResult<T>(IEnumerable<T>, Int32) Initializes a new instance of the QueryResult<T> class with the specified collection of result items and total count.

Top

Properties

  Name Description
Public property IncludedResults Gets or sets the included query results.
Public property RootResults Gets or sets the top-level query results.
Public property TotalCount Gets or sets the total number of rows for the original query without any paging applied to it. (Inherited from QueryResult.)

Top

Methods

  Name Description
Public method Equals (Inherited from Object.)
Protected method Finalize (Inherited from Object.)
Public method GetHashCode (Inherited from Object.)
Public method GetIncludedResults Retrieves the included results. (Overrides QueryResult.GetIncludedResults().)
Public method GetRootResults Retrieves the root results. (Overrides QueryResult.GetRootResults().)
Public method GetType (Inherited from Object.)
Protected method MemberwiseClone (Inherited from Object.)
Public method ToString (Inherited from Object.)

Top

Examples

Public Function MainPage()
    InitializeComponent()

    ' Create an EntityQuery of type Customer
    Dim query As EntityQuery(Of Customer) = _
        From c In _customerContext.GetCustomersQuery() _
        Where (c.Phone.StartsWith("583")())() _
        Order By (c.LastName) _
        Select c()

    ' Create and execute a LoadOperation of type Customer and load 'query'
    ' LoadBehavior is set to merge this query into the current cache
    Dim loadOp As LoadOperation = Me._customerContext.Load(query, LoadBehavior.MergeIntoCurrent, False)

    ' Create a new DomainOperationException for a Validation Error
    Dim opEx As DomainOperationException = New DomainOperationException( _
                                            "Validation Error", _
                                            OperationErrorStatus.ValidationError, _
                                            9466)
    ' Check if there are any ValidationErrors when loadOp was executed
    ' Then throw the DomainOperationException opEx
    If loadOp.ValidationErrors <> Empty Then
        Throw opEx
    End If

    ' Instantiate a new QueryResult of type Customer
    Dim qr As QueryResult(Of Customer) = New QueryResult(Of Customer)

    ' Populate the CustomerGrid with the QueryResult
    CustomerGrid.ItemsSource = qr.GetIncludedResults
// Create an EntityQuery of type Customer
EntityQuery<Customer> query =
    from c in _customerContext.GetCustomersQuery()
    where c.Phone.StartsWith("583")
    orderby c.LastName
    select c;

// Create and execute a LoadOperation of type Customer and load 'query'
// LoadBehavior is set to merge this query into the current cache
LoadOperation<Customer> loadOp = this._customerContext.Load(query, LoadBehavior.MergeIntoCurrent, false);

// Create a new DomainOperationException for a Validation Error
DomainOperationException opEx = new DomainOperationException(
    "Validation Error",
    OperationErrorStatus.ValidationFailed,
    0x000024FA);

// Check if there are any ValidationErrors when loadOp was executed
// Then throw the DomainOperationException opEx
if (loadOp.ValidationErrors != null)
{
    throw opEx;
}

// Instantiate a new QueryResult of type Customer
QueryResult<Customer> qr = new QueryResult<Customer>();

// Populate the CustomerGrid with the QueryResults
CustomerGrid.ItemsSource = qr.IncludedResults;

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

System.ServiceModel.DomainServices.Client Namespace