0

I want to filter on RetrieveAll result received from QueryExpressionin D365

Here is the code snippet:

private static List<IGrouping<string, Entity>> RetrieveDuplicates(IOrganizationService _crmService, DuplicateSearch duplicateSearch)
{
    QueryExpression query = GenerateQueryExpression(duplicateSearch.EntityLogicalName, duplicateSearch.DuplicatedColumnName, duplicateSearch.ColumnList.ToArray());
    Console.WriteLine("\n INFO: Finding duplicates is in progress ... \n");
    var results = _crmService.RetrieveAll(query)
                                    .OrderBy(e => e.GetAttributeValue<string>(duplicateSearch.DuplicatedColumnName))
                                    .ThenByDescending(e => e.GetAttributeValue<DateTime>("createdon"))
                                    .GroupBy(e => e.GetAttributeValue<string>(duplicateSearch.DuplicatedColumnName), e => e).ToList();

    WriteDuplicateRecordsInFile(results, duplicateSearch.EntityLogicalName);
    return results;
}

I'm thinking to pass duplicateSearch.DuplicatedColumnName as List<string> but do not know how I can set it in GroupBy.

But now, as per requirement, I want to GroupBy multiple key but don't know how can I do it.

Let me know if any other information is required.

Note: I want to use here dynamics attributes which will be selected by user.

I Love Stackoverflow
  • 6,738
  • 20
  • 97
  • 216
  • Possible duplicate of [Group By Multiple Columns](https://stackoverflow.com/questions/847066/group-by-multiple-columns) – JSteward Jul 11 '19 at 19:36
  • @JSteward: No it is not, as I do not have fix column neither datatype. I've just came to know above code will throw error for int value. – I Love Stackoverflow Jul 11 '19 at 19:44

0 Answers0