来自fetch xml的crm查询表达式

时间:2017-05-26 18:01:12

标签: c# dynamics-crm crm fetchxml query-expressions

我创建一个查询表达式,以便能够检索与特定帐户(测试工具)相关的所有合同。我现在的查询没有返回任何结果,尽管有1条记录与我正在寻找的匹配。我认为问题出在linkEntity本身,但我不确定。

我不再收到错误,因为我使用fetchxml作为我的guid来创建我的queryexpression,但是没有得到任何结果。



<?xml version="1.0"?>

<fetch distinct="true" mapping="logical" output-format="xml-platform" version="1.0">


<entity name="contract">

<attribute name="title"/>

<attribute name="statecode"/>

<attribute name="modifiedon"/>

<attribute name="modifiedby"/>

<attribute name="customerid"/>

<attribute name="createdon"/>

<attribute name="createdby"/>

<attribute name="hc_contracttype"/>

<attribute name="hc_contractsubtype"/>

<attribute name="activeon"/>

<attribute name="hc_contractlevel"/>

<attribute name="expireson"/>

<attribute name="hc_contractaccount"/>

<attribute name="hc_businessunit"/>

<attribute name="contractid"/>

<order descending="false" attribute="title"/>


<link-entity name="hc_account_contract" intersect="true" visible="false" to="contractid" from="contractid">


<link-entity name="account" to="accountid" from="accountid" alias="ab">


<filter type="and">

<condition attribute="name" value="Test Facility" operator="eq"/>

</filter>

</link-entity>

</link-entity>

</entity>

</fetch>
&#13;
&#13;
&#13;

LinkEntity accountLink = new LinkEntity()
        {
            Columns = new ColumnSet(true),
            LinkFromEntityName = "hc_account_contract",
            LinkFromAttributeName = "contractid",
            LinkToEntityName = "account",
            LinkToAttributeName = "accountid",
            EntityAlias = "ab"
        };

        accountLink.LinkCriteria.AddCondition("name", ConditionOperator.Equal, "Test Facility");

        QueryExpression exp = new QueryExpression("contract");
        exp.LinkEntities.Add(accountLink);
        exp.ColumnSet = new ColumnSet(true);

        EntityCollection results = _service.RetrieveMultiple(exp);
        Console.WriteLine("There are " + results.Entities.Count );
        foreach (Entity r in results.Entities)
        {
            Console.WriteLine(r.GetAttributeValue<string>("title"));
        }

0 个答案:

没有答案