从数据表中的LINQ不同的行 [英] Select distinct rows from datatable in Linq
本文介绍了从数据表中的LINQ不同的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想基于多个列(ATTRIBUTE1_NAME,ATTRIBUTE2_NAME),以获得不同的行,并使用LINQ到数据集从数据表获取数据行。
I am trying to get distinct rows based on multiple columns (attribute1_name, attribute2_name) and get datarows from datatable using Linq-to-Dataset.
我想要的效果是这样
attribute1_name attribute2_name
-------------- ---------------
Age State
Age weekend_percent
Age statebreaklaw
Age Annual Sales
Age Assortment
怎么做薄Linq到数据集?
How to do thin Linq-to-dataset?
推荐答案
如果它不是一个类型化数据集,那么你可能想要做这样的事情,使用LINQ到DataSet的扩展方法:
If it's not a typed dataset, then you probably want to do something like this, using the Linq-to-DataSet extension methods:
var distinctValues = dsValues.AsEnumerable()
.Select(row => new {
attribute1_name = row.Field<string>("attribute1_name"),
attribute2_name = row.Field<string>("attribute2_name")
})
.Distinct();
请确保您有一个使用System.Data这;
你的代码,以使Linq到数据集扩展方法开头的语句。
Make sure you have a using System.Data;
statement at the beginning of your code in order to enable the Linq-to-Dataset extension methods.
希望这有助于!
这篇关于从数据表中的LINQ不同的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文