简体   繁体   中英

Get distinct objects from list of dynamic objects

I'm trying to return a distinct list of dynamic objects. The object that I am filtering on is of type dynamic {System.Collections.Generic.List<object>} with each of its indexed items being of type object {System.Dynamic.ExpandoObject} .

An example of the data structure is found below:

Model.Object
    - [0]
        - Property 1 (value: aaa)
        - Property 2 (value: 123)
        - Property 3 (value: a123)
    - [1]
        - Property 1 (value: bbb)
        - Property 2 (value: 456)
        - Property 3 (value: a456)
    - [2]
        - Property 1 (value: ccc)
        - Property 2 (value: 123)
        - Property 3 (value: a123)`

I have tried the following, but with no success: var distinctResults = ((List<object>)Model.Object).GroupBy(elem => elem.Property 2).Select(group => group.First());

Any help please?

正如Lasse V. Karlsen所说,将其投射到List<dynamic>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM