简体   繁体   English

从动态对象列表中获取不同的对象

[英]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} . 我要过滤的对象是dynamic {System.Collections.Generic.List<object>}类型的,其每个索引项目都是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()); 我尝试了以下操作,但没有成功: var distinctResults = ((List<object>)Model.Object).GroupBy(elem => elem.Property 2).Select(group => group.First());

Any help please? 有什么帮助吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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