动态CRM - ms CRM查询表达式与链接实体



我在本地使用MS crm 2013。我在一个控制台应用程序工作,我需要做一个检索多个。

QueryExpression queexp = new QueryExpression();
ConditionExpression conexp1;
conexp1 = new ConditionExpression();
conexp1.AttributeName = "new_memberid";           
conexp1.Operator = ConditionOperator.Equal;
conexp1.Values.Add(id); 

查询有linkentities:

queexp.LinkEntities.Add(linkEntityAccount);
queexp.LinkEntities.Add(linkEntityArbet);

如果我删除上面关于链接实体的两行,查询工作正常。否则,它返回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;

最新更新