// 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()); }
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()); }
/// <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()); }
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()); }
/// <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()); }