如何获得LINQ查询 - 区别() [英] How to have a LINQ Query - Distinct()

查看:52
本文介绍了如何获得LINQ查询 - 区别()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

差距之后,我再次进入Visual C ++ 2010.现在我的目的是准备一个LINQ查询来从数据表中选择一个不同的值



在C#我的查询中



Hi, After a gap, again I entered to Visual C++ 2010. Now my intention is to prepare a LINQ Query to select a distinct value from a datatable

In C# My Query

var ProjLnkQry = (from P in MyClass1.ProjTbl.AsEnumerable() select P["proj_name"]).Distinct().ToList();





以上查询我尝试将其转换为VIsual C ++





The above query I try to convert it into VIsual C++

auto DistDepQry=(from v1 in MyGlobalData::ProjectTbl::AsEnumaerable() select v1["depart_name"])->Distinct()->ToList();





但未成功....感谢您的想法...



But not succeeded....Thanks for the ideas...

推荐答案



区别:



Hi
Distinct:

//distinct objects
List<objects> listObjects = (from obj in db.Objects                             
                             select obj).Distinct().ToList();
//distinct based on a specific propertie (in this case Mobile and Fax)
List<Objects> listObjects = (from obj in db.Objects                             
                                select obj).GroupBy(n => new {n.Mobile, n.Fax})
                                           .Select(g => g.FirstOrDefault())
                                           .ToList();

</objects>





希望有所帮助



Hope it helps


这篇关于如何获得LINQ查询 - 区别()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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