示例#1
0
        /// <summary>
        /// Build a query to get a list of child accounts of an account defined by its name
        /// </summary>
        /// <param name="parent"></param>
        /// <returns>The result from Dynamics server as string</returns>
        private string ListChildAccountsQuery(string parent)
        {
            var          xml    = new FetchXML(ENTITY);
            FetchElement entity = xml.EntityElement;

            entity.AddField("name");
            entity.AddField("accountid");
            FetchElement linkedEntiry = entity.AddLinkEntity("account", "accountid", "parentaccountid");
            FetchElement filter       = linkedEntiry.AddFilter();

            filter.AddCondition("name", "eq", value: parent);
            return(xml.ToQueryString());
        }
示例#2
0
        /// <summary>
        /// Query to get orders of a contact by its ID
        /// </summary>
        /// <param name="contactID"></param>
        /// <returns></returns>
        private string GetOrdersOfQuery(Guid contactID)
        {
            /*
             * <fetch version="1.0" mapping="logical">
             *  <entity name="salesorder">
             *      <attribute name="name" />
             *      <attribute name="description" />
             *      <attribute name="new_orderid" />
             *      <link-entity name="connection" from="record1id" to="salesorderid">
             *          <filter type="and">
             *              <condition attribute="record1objecttypecode" operator="eq" value="1088" />
             *              <condition attribute="record2objecttypecode" operator="eq" value="2" />
             *          </filter>
             *          <link-entity name="connectionrole" from="connectionroleid" to="record2roleid">
             *              <attribute name="name" alias="role" />
             *          </link-entity>
             *          <link-entity name="contact" from="contactid" to="record2id">
             *              <filter type="and">
             *                  <condition attribute="contactid" operator="eq" value="12ed419f-5863-e611-80e3-c4346bc516e8" />
             *              </filter>
             *          </link-entity>
             *      </link-entity>
             *  </entity>
             * </fetch>
             */

            var          xml    = new FetchXML(ENTITY);
            FetchElement entity = xml.EntityElement;

            entity.AddField("name")
            .AddField("description")
            .AddField("new_orderid");

            FetchElement linkedConnection = entity.AddLinkEntity("connection", "record1id", "salesorderid");
            FetchElement connectionFilter = linkedConnection.AddFilter();

            connectionFilter.AddCondition("record1objecttypecode", "eq", "1088")
            .AddCondition("record2objecttypecode", "eq", "2");
            linkedConnection.AddLinkEntity("connectionrole", "connectionroleid", "record2roleid")
            .AddField("name", "role");

            FetchElement linkedContact = linkedConnection.AddLinkEntity("contact", "contactid", "record2id");
            FetchElement contactFilter = linkedContact.AddFilter();

            contactFilter.AddCondition("contactid", "eq", contactID.ToString());

            return(xml.ToQueryString());
        }