You cannot use Contains method with LINQ for Dynamics CRM.
The General is correct, you can bring the entire entity set into memory and then perform your contains method. However, this is inefficient - especially when the entity sets increase after the system has gone live.
I have made the assumption that you are using early bound context, that is why you want to use LINQ, if this is correct then an option would be to do something like the following:
var usersList= new [] {
"User1",
"User2"
};
var systemUserQuery = new QueryExpression{
EntityName = SystemUser.EntityLogicalName,
ColumnSet = new ColumnSet("fullname","domainname" ....), //explicitly retrieve attributes
Criteria = {
Conditions = {
new ConditionExpression("fullname", ConditionOperator.In, userList)
}
}
};
var usersResponse = organizationService.RetrieveMultiple(systemUserQuery);
var systemUsers = usersResponse.Entities.Select(s => (SystemUser)s).ToArray();
This does not use LINQ in the expression to retrieve the data, however the query is executed remotely, and you do not need to retrieve the entire entity set. In the statement var systemUsers = usersResponse.Entities.Select(s => (SystemUser)s).ToArray();
The object type Microsoft.Xrm.Sdk.Entity
will be cast as the Early Bound Type SystemUser
and you can continue to use the objects as you any other Early Bound object.
When using the ConditionOperator.In
operator, the value supplied will need to be an array. You can declare the userList
variable as List<string>
as in your example. However, you will need to cast it before adding the object into the query.
Just a note the line ColumnSet = new ColumnSet("fullname","domainname" ....)
is where you select the attributes to retrieve in the request. If you do not specify the attribute here the property will be the default value after the cast.