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

我创建了 (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[]);

                 }

它只显示帐户名不显示注释和联系人


梵蒂冈之花
浏览 66回答 1
1回答

至尊宝的传说

确定使用以下查询仅检索客户及其相关联系人。我可以检索帐户及其相关联系人。现在获取这些帐户及其 ID,并使用第二个查询来获取 Notes(注释),您将为 Notes 做同样的事情。<fetch>&nbsp; <entity name="account" >&nbsp; &nbsp; <attribute name="name" />&nbsp; &nbsp; <link-entity name="contact" from="parentcustomerid" to="accountid" link-type="inner" >&nbsp; &nbsp; &nbsp; <attribute name="fullname" />&nbsp; &nbsp; </link-entity>&nbsp; </entity></fetch>检索笔记的查询:<fetch>&nbsp; <entity name="annotation" >&nbsp; &nbsp; <attribute name="filename" />&nbsp; &nbsp; <attribute name="documentbody" />&nbsp; &nbsp; <attribute name="isdocument" />&nbsp; &nbsp; <link-entity name="account" from="accountid" to="objectid" link-type="inner" >&nbsp; &nbsp; &nbsp; <filter type="and" >&nbsp; &nbsp; &nbsp; &nbsp; <condition attribute="accountid" operator="eq" value="AccountGuid" />&nbsp; &nbsp; &nbsp; </filter>&nbsp; &nbsp; </link-entity>&nbsp; </entity></fetch>C# 代码示例string fetch = @"&nbsp;&nbsp;&nbsp; &nbsp;<fetch>&nbsp; <entity name='account' >&nbsp; &nbsp; <attribute name='name' />&nbsp; &nbsp; <link-entity name='contact' from='parentcustomerid' to='accountid' link-type='inner' alias='Contact' >&nbsp; &nbsp; &nbsp; <attribute name='fullname' alias = 'Contact.Fullname' />&nbsp; &nbsp; </link-entity>&nbsp; </entity></fetch> ";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;EntityCollection Coll = CrmConn.RetrieveMultiple(new FetchExpression(fetch));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (Entity acunt in Coll.Entities)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Name of Account: " + acunt.GetAttributeValue<string>("name"));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine("Name of Contact: "&nbsp; + acunt.GetAttributeValue<AliasedValue>("Contact.Fullname").Value);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
打开App,查看更多内容
随时随地看视频慕课网APP