views:

53

answers:

1

Hi again,

When trying to do a query using LINQ in VB.net in order to select some employees of a datatable previously filled with a dataset I have a problem when using where clause. What I want is select all the employees of the datatable except those that appear in a list of excluded employees named CurrentExcludedEmployeesLst. So I follow these steps:

1.- First I fill my datatable 'employees' with the dataset. My dataset have a table with threee columns, EMPLID, NAME, DEPT.

          Dim employees As DataTable
          employees = Me.MyDataset.Tables("EMPLOYEESTABLE")

2.- I build the query:

    Dim employeeCollection As EnumerableRowCollection

    employeeCollection = 
          employees.AsEnumerable() _
            .Select(Function(employee As DataRow) New With _
            { _
              .EMPLID = employee.Field(Of String)("EMPLID"), _
              .NAME = employee.Field(Of String)("NAME"), _
              .TITLE = employee.Field(Of String)("DEPT") _
            }).Where(Function(employee As DataRow) NOT 
            CurrentExcludedEmployeesLst.Contains(employee.Field(Of String)("EMPLID")))

If I don't put the Where clause it works perfectly. My problem is when I want to filter using Where clause.

Thanks!

+1  A: 

If i understood correctly, you should try put your Where clause before Select.

miensol