Skip to content

Commit

Permalink
Fixed #800 Convert in SDK does not support NoLock. Here it does.
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Oct 25, 2022
1 parent 068da9f commit 38167ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions FetchXmlBuilder/DockControls/TreeBuilderControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ internal string GetFetchString(bool format, bool validate)
}
if (format)
{
XDocument doc = XDocument.Parse(xml);
xml = doc.ToString();
xml = XDocument.Parse(xml).ToString();
}
}
return xml;
Expand All @@ -272,22 +271,24 @@ internal MetadataBase SelectedMetadata()
return ctrl?.Metadata();
}

internal QueryExpression GetQueryExpression(string fetch = null, bool validate = true)
internal QueryExpression GetQueryExpression(bool validate = true)
{
if (fxb.Service == null)
{
throw new Exception("Must be connected to CRM to convert to QueryExpression.");
}
if (string.IsNullOrWhiteSpace(fetch))
{
fetch = GetFetchString(false, validate);
throw new Exception("Must be connected to Dataverse to convert to QueryExpression.");
}
var fetchdoc = GetFetchDocument();
var fetch = fetchdoc.OuterXml;
if (TreeNodeHelper.IsFetchAggregate(fetch))
{
throw new FetchIsAggregateException("QueryExpression does not support aggregate queries.");
}
var convert = (FetchXmlToQueryExpressionResponse)fxb.Execute(new FetchXmlToQueryExpressionRequest() { FetchXml = fetch });
return convert.Query;
var query = ((FetchXmlToQueryExpressionResponse)fxb.Execute(new FetchXmlToQueryExpressionRequest() { FetchXml = fetch })).Query;
if (fetchdoc.SelectSingleNode("fetch").AttributeBool("no-lock") == true && !query.NoLock)
{
query.NoLock = true;
}
return query;
}

internal void Init(string fetchStr, string layoutStr, string action, bool validate)
Expand Down
2 changes: 1 addition & 1 deletion FetchXmlBuilder/FetchXmlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ private string GetQueryExpressionCode()
var code = string.Empty;
try
{
var QEx = dockControlBuilder.GetQueryExpression(null, false);
var QEx = dockControlBuilder.GetQueryExpression(false);
code = QueryExpressionCodeGenerator.GetCSharpQueryExpression(QEx);
}
catch (FetchIsAggregateException ex)
Expand Down

0 comments on commit 38167ec

Please sign in to comment.