不同在一个特定的字段 [英] Distinct on a specific field

查看:114
本文介绍了不同在一个特定的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一类结构:

class MyEx{
public int Prop1;
public int Prop2;
public int Prop3
}

为prop1和支柱2始终是相同的,Prop3而变化。 这个类我想从一月底再检索应该是这样的。

Prop1 and Prop 2 are always the same , Prop3 varies. this class I want to retrieve from a longer the end should be something like

select new MyEx { Prop1=something;
                  Prop2= something2;
                  Prop3=something3;
}

问题是,something3不是唯一的,所以我想申请一个清晰到THW查询,以获得上述具有鲜明Prop3值类。 但是,这似乎并没有工作。 任何想法,为什么? 谢谢

the problem is that something3 is not unique , so I would like to apply a Distinct to thw query in order to obtain the class above with distinct Prop3 values. But this does not seem to work. Any ideas why? Thanks

推荐答案

我想你想<一href="http://$c$c.google.com/p/morelinq/source/browse/trunk/MoreLinq/DistinctBy.cs"><$c$c>DistinctBy MoreLINQ

var query = items.DistinctBy(x => x.Prop3);

这篇关于不同在一个特定的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆