So I try to make a group by select with count on how many posts has the same account and businessunit.
I get the account and business unit but when I ask for the count I get the error "the given key was not present in the dictionary."
I use the following fetchXml, which works perfectly in XrmToolbox FetchXML
var fetchXml = $@"<fetch top=""{getPosts}"" aggregate=""true""><entity name=""zync_accountowner""><attribute name=""zync_account"" alias=""Account"" groupby=""true"" /><attribute name=""zync_businessunit"" alias=""BusinessUnit"" groupby=""true"" /><attribute name=""zync_accountname"" alias=""ao_count"" aggregate=""count"" /><filter><condition attribute=""zync_account"" operator=""not-null"" /><!--<condition attribute=""createdon"" operator=""lt"" value=""{searchDate}"" />--></filter><order alias=""ao_count"" descending=""true"" /></entity></fetch>";
I then get the count with the following code and here is where the error happens.
var list = ctx.OrganizationService.RetrieveMultiple(new FetchExpression(fetchXml)); foreach (var item in list.Entities) { var count = (int)((AliasedValue)item["ao_count"]).Value; ctx.Trace($"Count: {count}"); }
For what I can google it's because that column only has null values on everything. But when I do the same fetchXml in XrmToolBox everything looks fine and I get a number on column for the Count.
What am I missing?