I want to get all common rows (including duplicate rows) between two data table having more than 45000 rows.
However, I want to skip "Column 2" and "all columns after column 6" out of comparison scope.But I am getting no rows as intersection result. Could any one suggest me where I am doing wrong?
Here's my code written:
CustomDataRowComparer myDRComparer = new CustomDataRowComparer();
var commonData = outputTable.AsEnumerable().Intersect(prevTable.AsEnumerable(), myDRComparer).CopyToDataTable();
public class CustomDataRowComparer : IEqualityComparer<DataRow>
{
public bool Equals(DataRow x, DataRow y)
{
for (int i = 0; i < 7; i++)
{
if (i !=1) // Don't want to consider this column for comparison
{
if (x[i].ToString() != y[i].ToString())
{
return false;
}
}
}
return true;
}
public int GetHashCode(DataRow obj)
{
return obj.ToString().GetHashCode();
}