3 回答
TA贡献1828条经验 获得超3个赞
你必须使用RetrieveMultiple方法 &QueryExpression来实现它。例如,下面的MSDN 代码示例是自我解释以获取联系人lastname = “Brown”
// Query using ConditionExpression and FilterExpression
ConditionExpression condition1 = new ConditionExpression();
condition1.AttributeName = "lastname";
condition1.Operator = ConditionOperator.Equal;
condition1.Values.Add("Brown");
FilterExpression filter1 = new FilterExpression();
filter1.Conditions.Add(condition1);
QueryExpression query = new QueryExpression("contact");
query.ColumnSet.AddColumns("firstname", "lastname");
query.Criteria.AddFilter(filter1);
EntityCollection result1 = _serviceProxy.RetrieveMultiple(query);
Console.WriteLine();Console.WriteLine("Query using Query Expression with ConditionExpression and FilterExpression");
Console.WriteLine("---------------------------------------");
foreach (var a in result1.Entities)
{
Console.WriteLine("Name: " + a.Attributes["firstname"] + " " + a.Attributes["lastname"]);
}
查询表达式用于检索多个记录的方法(例如IOrganizationService.RetrieveMultiple方法),用于对查询表达式(例如 BulkDeleteRequest)指定的结果集执行操作的消息中,并且当特定记录的 ID 不是已知。
TA贡献1868条经验 获得超4个赞
我使用查询得到了解决方案:
//Query for the GUID of the Account using Account Name
QueryExpression query = new QueryExpression("account");
string[] cols = { "accountid", "name" };
query.Criteria = new FilterExpression();
query.Criteria.AddCondition("name", ConditionOperator.Equal, "Account Name");
query.ColumnSet = new ColumnSet(cols);
var account = Service.RetrieveMultiple(query);
//Casting the reference to GUID
Guid accountId = (Guid)account[0].Attributes["accountid"];
这将使用帐户名称返回 Guid 信息。
- 3 回答
- 0 关注
- 129 浏览
添加回答
举报