Use the QueryByAttribute class
Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online
In Microsoft Dynamics 365 (online & on-premises), 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
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
Microsoft Dynamics 365
© 2016 Microsoft. All rights reserved. Copyright