QueryAttribute Class

WCF RIA Services

[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.]

Specifies that a DomainService method is a query method.


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

[AttributeUsageAttribute(AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field, AllowMultiple = false, 
	Inherited = true)]
public sealed class QueryAttribute : Attribute

The QueryAttribute type exposes the following members.

Public methodQueryAttributeInitializes a new instance of the QueryAttribute class.

Public propertyHasSideEffectsGets or sets a value that indicates whether the query method has side effects.
Public propertyIsComposableGets or sets a value that indicates whether the query method allows query composition.
Public propertyIsDefaultGets or sets a value indicating whether the query method should be treated as the default query when multiple query methods are available.
Public propertyResultLimitGets or sets the maximum number of results a query operation should return.
Public propertyTypeId (Inherited from Attribute.)

Public methodEquals (Inherited from Attribute.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Attribute.)
Public methodGetType (Inherited from Object.)
Public methodIsDefaultAttribute (Inherited from Attribute.)
Public methodMatch (Inherited from Attribute.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodToString (Inherited from Object.)

Explicit interface implemetationPrivate method_Attribute.GetIDsOfNames (Inherited from Attribute.)
Explicit interface implemetationPrivate method_Attribute.GetTypeInfo (Inherited from Attribute.)
Explicit interface implemetationPrivate method_Attribute.GetTypeInfoCount (Inherited from Attribute.)
Explicit interface implemetationPrivate method_Attribute.Invoke (Inherited from Attribute.)

You apply the QueryAttribute attribute to a method to indicate that the method is a query method, or to specify certain values for the query method. If your method matches the expected method signature for a query method, you do not have to apply the QueryAttribute. The RIA Services framework will infer that a method with the expected query signature should be treated as a query. You apply the IgnoreAttribute to a method to prevent the RIA Services framework from generating a domain operation for that method.

The following shows the expected signature for a query method:

Return value

IEnumerable<T>, IQueryable<T>, or entity


Any number

Name Prefix

Any name


[Query] (C#)


<Query()> (Visual Basic)


public IQueryable<Product> GetProducts() (C#)


Public Function GetProducts() As IQueryable(Of Product) (Visual Basic)

The QueryAttribute class enables you to set values that are used when processing the query request. You set the ResultLimit property to limit how many records are returned for a query. You may want to set this value to prevent a user from burdening the server with large query requests. For more information, see Building Secure Applications with WCF RIA Services. The IsComposable property enables you to specify whether code in the client project can modify the results of the query by using the query method within a new query. For example, when IsComposable is true, you can add a Where clause in client code to a query on the server that returns all of the records from a database table.

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