问题描述:

i'm new to LINQ and i'm facing a problem, here what i try to get:

Table A:

Field: Name A

Field: Id_A

Table B:

Field: Name B

Field: TableA_Id_A As New List(Of String)

Result Expected:

Field: New value true or false: to indicate if Id_A is include in Table B.TableA_Id_A

Field: Name A

Field: Id_A

In fact i want to list in grid the table A with a column which contains a checkbox and is checked if the item is include in table B (field TableA_Id_A).

网友答案:

Try this:

var result = TableA.Select(a=> New{ exist = TableB.TableA_Id_A.Contains(a.Id_A), NameA = a.NameA, IdA = a.IdA})

Check about linq synatx here: LINQ: .NET Language-Integrated Query
select new in linq

网友答案:

Finally i found another solution:

        Dim _result = (From _tblA In TableA _
                       From _tblB In TableB _
                       Let _NewValue = IIf(_tblB.TableA_Id_A.Contains(_tblA.Id_A), True, False) _
                      Select _tblA, _NewValue).Distinct.ToList

Thanks Niranjan Kala, i will try your solution.

相关阅读:
Top