使用LINQ过滤数据集

编程入门 行业动态 更新时间:2024-10-10 17:30:01
本文介绍了使用LINQ过滤数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个这样的数据集,只有一行 保健区: ___________________ 强度 钠 谷物 灵活性 强度 吸烟 压力 睡眠计划 有氧运动 少坐 餐食 部分 高脂 我必须从数据集中删除与数组dataobject中的数据匹配的行,例如Example

I have a dataset like this with just one row HealtArea: ___________________ Strenth Sodium Grains Flexibility Strength Smoking Stress Sleep Plan Cardio Sit Less Meals Portions High-Fat I have to remove from the dataset the rows that match data comming in a array dataobject, say for Example

<pre>MyHealth[] healtharray; healtharray[0].areaname = 'Sodium' healtharray[1].areaname = Smoking'

healtharray可以返​​回任意数量的项目. 2只是一个例子 LINQ可以用于将此数组作为过滤器应用于数据集,以仅获取与此数组项不匹配的列表吗?

healtharray can return any number of items. 2 is just an example Can LINQ be used to apply this array as a filter on the dataset to only get the list that does not match this array items?

推荐答案

我不知道关于LINQ的方法,但是一个简单的解决方案是将数据集转换为数据视图,从数组中构建一个漂亮的过滤器,然后使用DataView.RowFilter获得所需的结果 I don''t know about LINQ but a simple solution is to convert your dataset to a dataview, build a nice filter from your array and use DataView.RowFilter to get the desired results

如果要在客户端上进行过滤方面,您可以创建一个HashSet<string>来存储过滤条件. 然后在Where(LINQ)扩展方法中使用该方法,或者在where子句中使用该方法. 例如 If you want to filter on client side, you could create a HashSet<string> to store the filter criterion. Then use that in a Where (LINQ) extension method or analogous in a where clause. E.g. HashSet<string> exclude = new HaseSet<string>() { "..." , "..." , "..." ... }; ... var filteredQuery = myCollection.Where(record => !exclude.Contains(record.FieldToFilter)); ... foreach(var record in filteredQuery) { ... }

干杯 安迪

Cheers Andi

更多推荐

使用LINQ过滤数据集

本文发布于:2023-10-31 09:13:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545692.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   LINQ

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!