使用 ArrayList 作为 linq query "where" 关键字中的筛选器



我在ArrayList中有一些数据,我想使用where子句来过滤我的Linq查询。

下面我的Linq代码连接两个表,然后我使用Where子句过滤它们。现在我想通过使用Arraylist作为过滤器来进一步过滤这个查询。所以这个值来自arraylist

我希望"where"子句再进行一次比较,并且值来自数组列表:

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

这是我正在使用的代码。

谁能告诉我如何使用数组列表中的值进一步过滤我的Linq查询?

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
         };

您似乎正在使用链接到对象。所以你可以在数组列表

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

最新更新