Here is the way to convert to Query Expression to Fetch XML or Fetch XML to Query Expression.
// QueryExpression To Fetch XML Conversion.
var queryExpToFetchRequest = new QueryExpressionToFetchXmlRequest
{
Query = objQueryExpression
};
var conversionResponse = (QueryExpressionToFetchXmlResponse)objService.Execute(queryExpToFetchRequest);
string fetchXml = conversionResponse.FetchXml;
string strTestFetchXML = "<fetch distinct='false' no-lock='false' mapping='logical'><entity name='account'><attribute name='accountid' /></entity></fetch>";
// Fetch XML To QueryExpression Conversion.
var fetchToQueryExpressionRequest = new FetchXmlToQueryExpressionRequest
{
FetchXml = strTestFetchXML
};
var fetchToQueryExpressionResponse = (FetchXmlToQueryExpressionResponse)objService.Execute(fetchToQueryExpressionRequest);
QueryExpression objQueryExp = fetchToQueryExpressionResponse.Query;
--
Happy CRM'img
Gopinath
QueryExpression objQueryExpression = new QueryExpression("account");
objQueryExpression.ColumnSet = new ColumnSet("accountid");// QueryExpression To Fetch XML Conversion.
var queryExpToFetchRequest = new QueryExpressionToFetchXmlRequest
{
Query = objQueryExpression
};
var conversionResponse = (QueryExpressionToFetchXmlResponse)objService.Execute(queryExpToFetchRequest);
string fetchXml = conversionResponse.FetchXml;
string strTestFetchXML = "<fetch distinct='false' no-lock='false' mapping='logical'><entity name='account'><attribute name='accountid' /></entity></fetch>";
// Fetch XML To QueryExpression Conversion.
var fetchToQueryExpressionRequest = new FetchXmlToQueryExpressionRequest
{
FetchXml = strTestFetchXML
};
var fetchToQueryExpressionResponse = (FetchXmlToQueryExpressionResponse)objService.Execute(fetchToQueryExpressionRequest);
QueryExpression objQueryExp = fetchToQueryExpressionResponse.Query;
--
Happy CRM'img
Gopinath
install package nuget --> Microsoft.Dynamics.Sdk.Messages
ReplyDeleterequire
using Microsoft.Crm.Sdk.Messages
var fechtXML2 = ((QueryExpressionToFetchXmlResponse)service.Execute( (new QueryExpressionToFetchXmlRequest { Query = query }))).FetchXml;