Imir Hoxha
Imir Hoxha

Reputation: 1694

use ArrayList as filter in linq query "where" keyword

I have some data in an ArrayList and I would like to use that to filter my Linq query using the where clause.

My Linq code below joins two tables and then I filter them using the Where clause. Now I would like to FURTHER filter this query by using the Arraylist as a filter. So the value come from arraylist

I would like the "where" clause to take one more comparison and the value comes from an arraylist:

where rType.Field<string>("ProfSSCMName") == lbProfiles.SelectedValue && rType.Field<string>("Name") == lbHWTypes.SelectedValue && **arrayList.Tostring()**

This is the code that I am using.

Can anyone tell me how can I further filter my Linq query using the values in the arraylist?

joined = from rType in ds.Tables["HWTypes"].AsEnumerable()
         join rStock in ds.Tables["Stock"].AsEnumerable()
         on rType.Field<string>("ProductID") equals rStock.Field<string>("Partno")
         where rType.Field<string>("ProfSSCMName") == lbProfiles.SelectedValue && rType.Field<string>("Name") == lbHWTypes.SelectedValue
         select new
         {
             TagNumber = rStock.Field<string>("TagNumber"),
             SerialNumber = rStock.Field<string>("SerialNumber"),
             Partno = rStock.Field<string>("Partno"),
             PartType = rStock.Field<string>("PartType"),
             EcopartSubtype = rStock.Field<string>("EcopartSubtype"),
             AzertyQuerty = rStock.Field<string>("Azerty/Querty"),
             ProductID = rType.Field<string>("ProductID"),
             Name = rType.Field<string>("Name"),
             SCCMKeyboard = rType.Field<string>("SCCMKeyboard"),
             DisplayName = rType.Field<string>("DisplayName"),
             ProfSSCMName = rType.Field<string>("ProfSSCMName"),
             TagNameDisplayName = rStock.Field<string>("TagNumber") + " " + rType.Field<string>("DisplayName")

             // add the other columns you need here
         };

Upvotes: 3

Views: 1356

Answers (1)

Adam Mills
Adam Mills

Reputation: 8109

You seem to be using Linq-To-Objects. So you can just use contains on the arraylist

where rType.Field<string>("ProfSSCMName") == lbProfiles.SelectedValue 
&& rType.Field<string>("Name") == lbHWTypes.SelectedValue 
&& arrayList.Contains( rType.Field<string>("Name") )

Upvotes: 2

Related Questions