检索单个Query中的所有记录

问题描述 投票:0回答:1

我创建了(1)2个账户(第1个将是第2个账户的父母)(2)创建了2个联系人(第1个联系人将是第1个账户,第2个账户是第2个账户)(3)创建了一个注释并将其与Parent关联帐户(4)创建两个备注并将其与第二个联系人关联

现在我想在单个查询中检索所有记录..

我试过但没有得到结果..

var fetch = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
                  "<entity name='account'>" +
                    "<attribute name='name' />" +
                    "<attribute name='primarycontactid' />" +
                    "<attribute name='telephone1' />" +
                    "<attribute name='accountid' />" +
                    "<order attribute='name' descending='false' />" +
                    "<link-entity name='contact' from='parentcustomerid' to='accountid' link-type='inner' alias='bd'>" +
                    "<attribute name='fullname' />" +
                      "<link-entity name='annotation' from='objectid' to='contactid' link-type='inner' alias='be'>" +
                        "<filter type='and'>" +
                          "<condition attribute='subject' operator='not-null' />" +
                        "</filter>" +
                      "</link-entity>" +
                    "</link-entity>" +
                  "</entity>" +
                "</fetch>";

 EntityCollection Coll = CrmConn.RetrieveMultiple(new FetchExpression(fetch));

                foreach (Entity acunt in Coll.Entities)
                {
                    Console.WriteLine("Name of Account: " + acunt.GetAttributeValue<string>("name"));
                    Console.WriteLine("Name of Contact: "  +acunt.GetAttributeValue<string>("fullname"));
                    Console.WriteLine("Name of Notes: " + acunt.GetAttributeValue<string>("subject"));
                    //Console.WriteLine("contact: ", Coll.Entities[]);
                 }

它只显示帐户名称,不显示备注和联系人

c# xml-parsing dynamics-crm
1个回答
0
投票

确定使用以下查询仅检索帐户及其相关联系人。我可以检索帐户及其相关的联系人。现在拿这些帐户和它的ID并使用第二个查询来获取Notes(注释)你将为Notes做同样的事情。

<fetch>
  <entity name="account" >
    <attribute name="name" />
    <link-entity name="contact" from="parentcustomerid" to="accountid" link-type="inner" >
      <attribute name="fullname" />
    </link-entity>
  </entity>
</fetch>

查询以检索Notes:

<fetch>
  <entity name="annotation" >
    <attribute name="filename" />
    <attribute name="documentbody" />
    <attribute name="isdocument" />
    <link-entity name="account" from="accountid" to="objectid" link-type="inner" >
      <filter type="and" >
        <condition attribute="accountid" operator="eq" value="AccountGuid" />
      </filter>
    </link-entity>
  </entity>
</fetch>

C#代码示例

string fetch = @"  
   <fetch>
  <entity name='account' >
    <attribute name='name' />
    <link-entity name='contact' from='parentcustomerid' to='accountid' link-type='inner' alias='Contact' >
      <attribute name='fullname' alias = 'Contact.Fullname' />
    </link-entity>
  </entity>
</fetch> ";

           EntityCollection Coll = CrmConn.RetrieveMultiple(new FetchExpression(fetch));

                foreach (Entity acunt in Coll.Entities)
                {
                    Console.WriteLine("Name of Account: " + acunt.GetAttributeValue<string>("name"));
                    Console.WriteLine("Name of Contact: "  + acunt.GetAttributeValue<AliasedValue>("Contact.Fullname").Value);
                 }
© www.soinside.com 2019 - 2024. All rights reserved.