Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Use the QueryByAttribute Class

[Applies to: Microsoft Dynamics CRM 2011]

In Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online, you can use the QueryByAttribute class to build queries that test a set of attributes against a set of values. Use this class with the RetrieveMultiple method or the IOrganizationService.RetrieveMultipleRequest method.

The following table lists the properties that you can set to create a query expression using the QueryByAttribute class.


Property Description


Specifies which type of entity is retrieved. A query expression can only retrieve a collection of one entity type. You can also pass this value by using the QueryExpression constructor.


Specifies the set of attributes (columns) to retrieve.


Specifies the set of attributes selected in the query.


Specifies the attribute values to look for when the query is executed.


Specifies the order in which the records are returned from the query.


Specifies the number of pages and the number of records per page returned from the query.

The following code example shows how to use the QueryByAttribute class.

//  Create query using querybyattribute
    QueryByAttribute querybyexpression = new QueryByAttribute("account");
    querybyexpression.ColumnSet = new ColumnSet("name", "address1_city", "emailaddress1");
//  Attribute to query
//  Value of queried attribute to return
//  Query passed to the service proxy
    EntityCollection retrieved = _serviceProxy.RetrieveMultiple(querybyexpression);
//  Iterate through returned collection
    foreach (var c in retrieved.Entities)
       System.Console.WriteLine("Name: " + c.Attributes["name"]);
       System.Console.WriteLine("Address: " + c.Attributes["address1_city"]);
       System.Console.WriteLine("E-mail: " + c.Attributes["emailaddress1"]);

See Also

Microsoft Dynamics CRM 2011
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.