为了账号安全,请及时绑定邮箱和手机立即绑定

在单个查询中检索所有记录

在单个查询中检索所有记录

C#
梵蒂冈之花 2022-11-21 16:24:40
我创建了 (1) 2 个帐户(第一个将成为第二个帐户的父级)(2) 创建了 2 个联系人(关联第一个联系人将是第一个帐户,第二个联系人将是第二个帐户)(3) 创建了一个笔记并将其与父级关联帐户 (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[]);                 }它只显示帐户名不显示注释和联系人
查看完整描述

1 回答

?
至尊宝的传说

TA贡献1789条经验 获得超10个赞

确定使用以下查询仅检索客户及其相关联系人。我可以检索帐户及其相关联系人。现在获取这些帐户及其 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>

检索笔记的查询:


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

                 }


查看完整回答
反对 回复 2022-11-21
  • 1 回答
  • 0 关注
  • 60 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信