示例#1
0
        // fetchXml version for getting ordered products
        private string GetOderDetails(Guid orderID)
        {
            var          xml    = new FetchXML(ENTITY);
            FetchElement entity = xml.EntityElement;

            entity.AddFilter()
            .AddCondition("salesorderid", "eq", orderID.ToString());
            entity.AddLinkEntity("product", "productid", "productid").AddField("name", "product");
            return(xml.ToQueryString());
        }
示例#2
0
        public void CanCreateWithAttributes()
        {
            var attributes = new Dictionary <string, string>
            {
                { "name", "salesorderdetail" },
                { "from", "salesorderid" },
                { "to", "salesorderid" }
            };
            FetchElement element = new FetchElement("link-entity", attributes);

            Assert.Equal(@"<link-entity name=""salesorderdetail"" from=""salesorderid"" to=""salesorderid"" />", element.DOC.OuterXml);
        }
示例#3
0
        public void CanAddFragment()
        {
            const string result = @"<fetch version='1.0' mapping='logical'><entity name='test'><link-entity name='test' /></entity></fetch>";
            XmlDocument  doc    = new XmlDocument();

            doc.LoadXml(result);

            var          xml     = new FetchXML("test");
            FetchElement frgment = new FetchElement("link-entity", "test");

            xml.EntityElement.AddFragment(frgment);
            Assert.Equal("?fetchXml=" + doc.OuterXml, xml.ToQueryString());
        }
示例#4
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());
        }
示例#5
0
        public void CanProduceXml()
        {
            const string result = @"<fetch version='1.0' mapping='logical'><entity name='test'><attribute name='name' /><attribute name='description' /></entity></fetch>";
            XmlDocument  doc    = new XmlDocument();

            doc.LoadXml(result);

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

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

            Assert.Equal("?fetchXml=" + doc.OuterXml, xml.ToQueryString());
        }
示例#6
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());
        }
示例#7
0
        /// <summary>
        /// A link-entity which can be added to the main order query to get names of ordered product
        /// </summary>
        /// <returns></returns>
        // Not tested used yet
        private FetchElement OrderLineQuery()
        {
            var attributes = new Dictionary <string, string>
            {
                { "name", "salesorderdetail" },
                { "from", "salesorderid" },
                { "to", "salesorderid" }
            };
            FetchElement linkedOrderLine = new FetchElement("link-entity", attributes);

            linkedOrderLine.AddField("priceperunit")
            .AddField("quantity")
            .AddField("manualdiscountamount_base");

            FetchElement linkedProduct = linkedOrderLine.AddLinkEntity("product", "productid", "productid");

            linkedProduct.AddField("name", "product");
            return(linkedOrderLine);
        }
示例#8
0
        public void CanCreateFragment()
        {
            FetchElement frgment = new FetchElement("link-entity", "test");

            Assert.Equal(@"<link-entity name=""test"" />", frgment.DOC.OuterXml);
        }