gpt4 book ai didi

c# - 从 Linq 中的数据表中选择不同的行

转载 作者:可可西里 更新时间:2023-11-01 03:03:46 25 4
gpt4 key购买 nike

我正在尝试根据多列(attribute1_name、attribute2_name)获取不同的行,并使用 Linq-to-Dataset 从数据表中获取数据行。

Screenshot

我想要这样的结果

attribute1_name    attribute2_name
-------------- ---------------

Age State
Age weekend_percent
Age statebreaklaw
Age Annual Sales
Age Assortment

如何精简 Linq 到数据集?

最佳答案

如果它不是类型化的数据集,那么您可能想要使用 Linq-to-DataSet 扩展方法来做这样的事情:

var distinctValues = dsValues.AsEnumerable()
.Select(row => new {
attribute1_name = row.Field<string>("attribute1_name"),
attribute2_name = row.Field<string>("attribute2_name")
})
.Distinct();

确保您在代码开头有一个 using System.Data; 语句,以启用 Linq-to-Dataset 扩展方法。

希望这对您有所帮助!

关于c# - 从 Linq 中的数据表中选择不同的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3242892/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com