Share via


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

Specifies that a DomainService method is a query method.

Inheritance Hierarchy

System.Object
  System.Attribute
    System.ServiceModel.DomainServices.Server.QueryAttribute

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

Syntax

'Declaration
<AttributeUsageAttribute(AttributeTargets.Method Or AttributeTargets.Property Or AttributeTargets.Field, AllowMultiple := False,  _
    Inherited := True)> _
Public NotInheritable Class QueryAttribute _
    Inherits Attribute
'Usage
Dim instance As QueryAttribute
[AttributeUsageAttribute(AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field, AllowMultiple = false, 
    Inherited = true)]
public sealed class QueryAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method|AttributeTargets::Property|AttributeTargets::Field, AllowMultiple = false, 
    Inherited = true)]
public ref class QueryAttribute sealed : public Attribute
[<SealedAttribute>]
[<AttributeUsageAttribute(AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field, AllowMultiple = false, 
    Inherited = true)>]
type QueryAttribute =  
    class
        inherit Attribute
    end
public final class QueryAttribute extends Attribute

The QueryAttribute type exposes the following members.

Constructors

  Name Description
Public method QueryAttribute Initializes a new instance of the QueryAttribute class.

Top

Properties

  Name Description
Public property HasSideEffects Gets or sets a value that indicates whether the query method has side effects.
Public property IsComposable Gets or sets a value that indicates whether the query method allows query composition.
Public property IsDefault Gets or sets a value indicating whether the query method should be treated as the default query when multiple query methods are available.
Public property ResultLimit Gets or sets the maximum number of results a query operation should return.
Public property TypeId (Inherited from Attribute.)

Top

Methods

  Name Description
Public method Equals (Inherited from Attribute.)
Protected method Finalize (Inherited from Object.)
Public method GetHashCode (Inherited from Attribute.)
Public method GetType (Inherited from Object.)
Public method IsDefaultAttribute (Inherited from Attribute.)
Public method Match (Inherited from Attribute.)
Protected method MemberwiseClone (Inherited from Object.)
Public method ToString (Inherited from Object.)

Top

Explicit Interface Implementations

  Name Description
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.)

Top

Remarks

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

Parameters

Any number

Name Prefix

Any name

Attribute

[Query] (C#)

-or-

<Query()> (Visual Basic)

Example

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

-or-

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.

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.Server Namespace