You can perform minus operation between two datatables as you do in RDBMS.
public DataTable getLinq(DataTable dt1, DataTable dt2)
{
DataTable dtMerged =
(from a in dt1.AsEnumerable()
join b in dt2.AsEnumerable()
on
a["Query"].ToString() equals b["Query"].ToString()
into g
where g.Count() ==0
select a).CopyToDataTable();
return dtMerged;
}
Working example:
Consider datatable dt1 is having the data
Place | id | time |
---|
Russia | 1 | 22:10 |
Italy | 2 | 23:10 |
Australia | 2 | 00:10 |
India | 1 | 01:10 |
Pakistan | 6 | 02:10 |
Sri lanka | 1 | 03:10 |
China | 4 | 04:10 |
London | 1 | 05:10 |
Germany | 6 | 06:10 |
Iraq | 1 | 07:10 |
America | 4 | 08:10 |
India | 1 | 09:10 |
Consider datatable dt2 is having the data
Now we are going to perform MINUS operation. We are going to retrieve the rows from dt1 by neglecting the places from dt2.
public DataTable getLinq(DataTable dt1, DataTable dt2)
{
DataTable dtMerged = (from a in dt1.AsEnumerable()
join b in dt2.AsEnumerable()
on a["Place"].ToString() equals b["Place"].ToString()
into g
where g.Count() == 0
select a).CopyToDataTable();
return dtMerged;
}
Result set :
Place | id | time |
---|
Russia | 1 | 30-12-1899 22:10 |
Australia | 2 | 01-01-1900 00:10 |
Pakistan | 6 | 01-01-1900 02:10 |
Sri lanka | 1 | 01-01-1900 03:10 |
China | 4 | 01-01-1900 04:10 |
London | 1 | 01-01-1900 05:10 |
Germany | 6 | 01-01-1900 06:10 |
America | 4 | 01-01-1900 08:10 |