0

Let's say both DataTable A and B has a column ID.

Is there any concise way using Linq (Not for loop) to find records in A which is (or not) in B base on ID!?

For example:

A
---
ID     Value
2        7
2        3
3        5
5        6
7        2
7        5
7        4

B
---
ID     Value
1        3
1        9
2        4
4        6
4        2
7        4
9        3

Results from A which is ALSO in B base on ID
---
ID     Value
2        7
2        3
7        2
7        5
7        4

Results from A which is NOT in B base on ID
---
ID     Value
3        5
5        6
halfer
  • 19,824
  • 17
  • 99
  • 186
Pikachu620
  • 483
  • 4
  • 17
  • Possible duplicate of [Get the difference between two lists using LINQ](https://stackoverflow.com/questions/7347386/get-the-difference-between-two-lists-using-linq) – dsdel Apr 20 '18 at 04:48
  • Thanks! Let me go see what I can do with it and update here! – Pikachu620 Apr 20 '18 at 04:54

1 Answers1

1

Using the Any method may work for you.

Something like this, obviously variable depending on your data structure:

AInB = A.Where(a => B.Any(b => b.ID == a.ID));

ANotInB = A.Where(a => !B.Any(b => b.ID == a.ID));
halfer
  • 19,824
  • 17
  • 99
  • 186
Lyons
  • 36
  • 2