我在内部使用MS crm 2013。我正在一个控制台应用程序,我需要做一个检索多个。
QueryExpression queexp = new QueryExpression();
ConditionExpression conexp1;
conexp1 = new ConditionExpression();
conexp1.AttributeName = "new_memberid";
conexp1.Operator = ConditionOperator.Equal;
conexp1.Values.Add(id);
查询具有关键性:
queexp.LinkEntities.Add(linkEntityAccount);
queexp.LinkEntities.Add(linkEntityArbet);
如果我删除上面关于linkentities的两行,查询工作正常。否则,它返回0结果。 我该如何解决这个问题?
答案 0 :(得分:0)
您需要明确指定要添加的LinkEntities。例如:
//Create a query expression specifying the link entity alias and the columns of the link entity that you want to return
QueryExpression qe = new QueryExpression();
qe.EntityName = "account";
qe.ColumnSet = new ColumnSet();
qe.ColumnSet.Columns.Add("name");
qe.LinkEntities.Add(new LinkEntity("account", "contact", "primarycontactid", "contactid", JoinOperator.Inner));
qe.LinkEntities[0].Columns.AddColumns("firstname", "lastname");
qe.LinkEntities[0].EntityAlias = "primarycontact";
EntityCollection ec = _orgService.RetrieveMultiple(qe);
第二种方法是使用LINQ:
OrganizationServiceContext orgSvcContext = new OrganizationServiceContext(xProxy);
var result = from c in orgSvcContext.CreateQuery("entityname")
//where....
select c;
EntityCollaction xEntityCol = result;