Dynamics crm ms crm queryexpression与LinkEntite

Dynamics crm ms crm queryexpression与LinkEntite,dynamics-crm,Dynamics Crm,我正在使用MS crm 2013内部部署。我正在开发一个控制台应用程序,在那里我需要进行多次检索 QueryExpression queexp = new QueryExpression(); ConditionExpression conexp1; conexp1 = new ConditionExpression(); conexp1.AttributeName = "new_memberid"; conexp1.Operator = ConditionOperato

我正在使用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个结果。
如何解决此问题?

您需要明确指定要添加的链接。例如:

//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;

当然,我知道我没有在问题中添加它。我想这是微软的错误,你所遇到的已经在我的代码里了。但是,始终0个记录被重设。当我删除linkenties时,正如您提到的示例中预期的那样,我得到了一条记录,没有条件表达式。这就是为什么它会起作用。尝试添加LinkEntite和特定的conditionexpression。将检索0条记录。您听说过xrm抓取程序吗?我知道了。如果linkentity查找为空,则crmservice根本无法检索任何内容。我认为Microsoft在这里的设计有误,它应该检索包含其他列的记录。