Last active
January 16, 2019 16:51
-
-
Save rappen/11a89553ff26c400c0c100db43c442ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Crm.Sdk.Messages; | |
using Microsoft.Xrm.Sdk; | |
using Microsoft.Xrm.Sdk.Query; | |
using System.Xml; | |
namespace Rappen.Xrm.Extensions | |
{ | |
public static class ServiceExtensions | |
{ | |
/// <summary> | |
/// Converts from QueryBase to FetchXML, removing invalid attribute useraworderby to validate with fetch.xsd | |
/// </summary> | |
/// <param name="organizationService"></param> | |
/// <param name="query"></param> | |
/// <returns></returns> | |
public static string QueryExpressionToFetchXml(this IOrganizationService organizationService, QueryBase query) | |
{ | |
QueryExpressionToFetchXmlRequest request = new QueryExpressionToFetchXmlRequest() | |
{ | |
Query = query | |
}; | |
QueryExpressionToFetchXmlResponse response = (QueryExpressionToFetchXmlResponse)organizationService.Execute(request); | |
var doc = new XmlDocument(); | |
doc.LoadXml(response.FetchXml); | |
var fetchnode = doc.SelectSingleNode("fetch"); | |
if (fetchnode != null && fetchnode.Attributes["useraworderby"] != null) | |
{ | |
fetchnode.Attributes.RemoveNamedItem("useraworderby"); | |
} | |
return doc.OuterXml; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment