2017-08-08 58 views
-1

我在一个项目上工作,我觉得他们做这样的查询:内连接不Dynamics CRM中查询工作

LinkEntity link = LinkEntity("table1", "account", "table1acountid", "accountid", JoinOperator.Inner) 

link.LinkCriteria.AddCondition("accountid", ConditionOperator.Equal, Id); 

表1和客户之间的关系是1:N(我们有一个查询以表1形式记帐)

查询的结果总是为空,但是当我将Inner更改为Leftouter时,它起作用。

查询是否正确使用内部连接?在这种情况下它应该返回table1的记录吗?

+1

是否可以从表和您的研究结果提供的样本数据?链接标准看起来不正确。 “AddCondition”中的“Id”不应该是“table1accountid”吗? 'Leftouter'可能不会返回你想要的。 –

回答

0

您添加的条件不是必需的,如果仅用于返回与table1关联的帐户,该帐户隐含地来自LinkEntity语句。 我想你在第一行中也缺少new指令。 建议您使用FetchXML Builder for XrmToolBox来组成查询,然后可以将其转换为QueryExpression代码。

我想这是你想要的查询(添加一些属性,返回等)

<fetch > 
    <entity name='' > 
    <filter> 
     <condition attribute='accountid' operator='eq' value='Id' /> 
    </filter> 
    <link-entity name='table1' from='table1accountid' to='accountid' link-type='inner' /> 
    </entity> 
</fetch>