在linq查询“where”关键字中使用ArrayList作为过滤器

时间:2012-12-20 13:21:50

标签: asp.net linq

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

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

我希望“where”子句再进行一次比较,并且值来自一个arraylist:

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

这是我正在使用的代码。

有谁能告诉我如何使用arraylist中的值进一步过滤我的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
         };

1 个答案:

答案 0 :(得分:2)

您似乎正在使用Linq-To-Objects。 所以你可以在arraylist上使用contains

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