Share via


Use the QueryByAttribute class

 

Applies To: Dynamics CRM 2015

In Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online 2015 Update, 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

EntityName

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.

ColumnSet

Specifies the set of attributes (columns) to retrieve.

Attributes

Specifies the set of attributes selected in the query.

Values

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

Orders

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

PageInfo

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    querybyexpression.Attributes.AddRange("address1_city");//  Value of queried attribute to return    querybyexpression.Values.AddRange("Detroit");    //  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

QueryByAttribute
Build queries with QueryExpression
Use the QueryExpression class

© 2016 Microsoft. All rights reserved. Copyright