Search code examples
c#linqdynamics-crm-2015fetchxmlquery-expressions

Is it possible to retrieve distinct attribute valued records of a custom entity in Dynamics Crm without using sql query?


I want to apply distinct method on attribute values. I tried queryexpression, linq query and fetchxml but I could not find a solution for c#.

For example if I have following records

row1 -> A | E | A  
row2 -> B | D | A  
row3 -> C | C | B  
row4 -> D | B | C  
row5 -> E | A | D
row6 -> E | A | E 

I only want to retrieve row1, row3, row4, row5, row6 and not row2.


Solution

  • The Distinct command will only work on a per row basis. If you truly wanted it to be a column level distinction, you have two options:

    1. Perform two queries, one that selects on the columns you desire the distinction on and another to retrieve the rest of the columns based on the Id's of the first query -or-
    2. Perform a single query, and use code on the client side to parse out the rows that contain the distinct values you're looking for.