Export (0) Print
Expand All
4 out of 5 rated this helpful - Rate this topic

CrmService.RetrieveMultiple Method

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Retrieves a collection of entity instances based on the specified query criteria.

Syntax

[Visual Basic .NET]
Public Function RetrieveMultiple(
  ByVal query As QueryBase
) As BusinessEntityCollection
[C#]
public BusinessEntityCollection RetrieveMultiple(
  QueryBase  query
);

Parameters

query

Specifies either a QueryExpression or a QueryByAttribute object derived from the QueryBase class. This is the query to be executed for an entity. The QueryExpression or QueryByAttribute object contains the type information for the entity.

Return Value

A BusinessEntityCollection that is a collection of entities of the type of specified in the query parameter.

Remarks

Use this method to retrieve one or more entity instances based on criteria specified in the QueryExpression.

For better performance, use this method instead of using the Execute method with the RetrieveMultiple message.

To perform this action, the caller must have access rights on the entity instance specified in the request class. For a list of required privileges, see Retrieve Privileges.

The ColumnSet specified within the QueryExpression can only include the objects of the type of the calling entity. For more information, see Using ColumnSet.

Example

The following example demonstrates the use of the RetrieveMultiple method.

[C#]
// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0; 
token.OrganizationName = "AdventureWorksCycle";
 
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create the ColumnSet that indicates the properties to be retrieved.
ColumnSet cols = new ColumnSet();

// Set the properties of the ColumnSet.
cols.Attributes = new string [] {"fullname", "contactid"};

// Create the ConditionExpression.
ConditionExpression condition = new ConditionExpression();

// Set the condition for the retrieval to be when the contact's address' city is Sammamish.
condition.AttributeName = "address1_city";
condition.Operator = ConditionOperator.Like;
condition.Values = new string [] {"Sammamish"};

// Create the FilterExpression.
FilterExpression filter = new FilterExpression();

// Set the properties of the filter.
filter.FilterOperator = LogicalOperator.And;
filter.Conditions = new ConditionExpression[] {condition};

// Create the QueryExpression object.
QueryExpression query = new QueryExpression();

// Set the properties of the QueryExpression object.
query.EntityName = EntityName.contact.ToString();
query.ColumnSet = cols;
query.Criteria = filter;

// Retrieve the contacts.
BusinessEntityCollection contacts = service.RetrieveMultiple(query);
[Visual Basic .NET]
' Set up the CRM Service.
Dim token As New CrmAuthenticationToken()
' You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0
token.OrganizationName = "AdventureWorksCycle";
 
Dim service As New CrmService()
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials

' Create the ColumnSet that indicates the properties to be retrieved.
Dim cols As New ColumnSet()

' Set the properties of the ColumnSet.
cols.Attributes = New String() {"fullname", "contactid"}

' Create the ConditionExpression.
Dim condition As New ConditionExpression()

' Set the condition for the retrieval to be when the contact's address' city is Sammamish.
condition.AttributeName = "address1_city"
condition.Operator = ConditionOperator.Like
condition.Values = New String() {"Sammamish"}

' Create the FilterExpression.
Dim filter As New FilterExpression()

' Set the properties of the filter.
filter.FilterOperator = LogicalOperator.And
filter.Conditions = New ConditionExpression() {condition}

' Create the QueryExpression object.
Dim query As New QueryExpression()

' Set the properties of the QueryExpression object.
query.EntityName = EntityName.contact.ToString()
query.ColumnSet = cols
query.Criteria = filter

' Retrieve the contacts.
Dim contacts As BusinessEntityCollection = service.RetrieveMultiple(query)

Requirements

Namespace: CrmService

See Also

Concepts

Tasks

Reference


© 2010 Microsoft Corporation. All rights reserved.


Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.