2015-06-03 44 views
0

我在本地使用MS crm 2013。我正在一个控制台应用程序,我需要做一个retrievemultiple。ms crm queryexpression with linkentiites

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

如果我删除有关linkentities上述两行,查询的工作fine.Otherwise,则返回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; 
+0

Ofcourse,我有我没有的问题在这里添加它。我认为这是一些微软错误, –

+0

比现在的工作? – Unlockedluca

+0

你提到的是我的代码已经。但是,总是记录0个记录。当我删除linkentities我得到一个记录按预期 –