Dynamics CRM 365 的 QueryExpression 使用


 1             QueryExpression query = new QueryExpression("contact");
 2             query.ColumnSet.AddColumns("firstname", "lastname", "address1_city");
 3             query.Criteria.AddCondition("address1_city", ConditionOperator.Equal, "Redmond");
 4 
 5             FilterExpression childFilter = query.Criteria.AddFilter(LogicalOperator.Or);
 6             childFilter.AddCondition("lastname", ConditionOperator.Equal, "Tharpe");
 7             childFilter.AddCondition("lastname", ConditionOperator.Equal, "Brown");
 8 
 9             // Pass query to service proxy 
10             EntityCollection results = _serviceProxy.RetrieveMultiple(query);
11             Console.WriteLine();
12             Console.WriteLine("Query using QE with multiple conditions and filters");
13             Console.WriteLine("---------------------------------------");
14 
15             // Print results 
16             foreach (var a in results.Entities)
17             {
18                 Console.WriteLine("Name: {0} {1}", a.GetAttributeValue<string>("firstname"), a.GetAttributeValue<string>("lastname"));
19                 Console.WriteLine("City: {0}", a.GetAttributeValue<string>("address1_city"));
20             }
21             Console.WriteLine("---------------------------------------");