Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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

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?
Posted
Updated 8-Oct-13 10:48am
v2

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
 
Share this answer
 
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.

C#
HashSet<string> exclude = new HaseSet<string>()
{ "..."
, "..."
, "..."
...
};
...
var filteredQuery = myCollection.Where(record => !exclude.Contains(record.FieldToFilter));
...
foreach(var record in filteredQuery)
{
   ...
}

Cheers
Andi
 
Share this answer
 
v2
Comments
Member 10323977 8-Oct-13 22:50pm    
The array is dynamic. Its coming from the database. Not sure how I can set a Hashset like that. Yeah this code is front end.
Andreas Gieriet 9-Oct-13 2:19am    
Have you looked up the hash set documentation? You should be able to do something like this:
HashSet<string> exclude = new HaseSet<string>(myExcludeTable.Select(record=>record.MyExcludeField));</string>.
Cheers
Andi
Andreas Gieriet 9-Oct-13 2:18am    
Deleted...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900