This method will take two table as input. This function will provide Left Outer join between two table and also performs any kind of math operation needed on the table. For example : along with the left outer join we may want to add columns of two table to produce different column value. In below example two columns from two different table are added . After the Left Outer join, Left Table will contain added value .
public static DataTable LeftOuterJoinTables(DataTable LeftTable, DataTable RightTable)
{
DataTable dtJoinedTable = null;
var resultQuery = from TableA in LeftTable.AsEnumerable()
join TableB in RightTable.AsEnumerable()
on new
{
ColumnA = TableA.Field
ColumnB = TableA.Field
}
equals new
{
ColumnA = TableB.Field
ColumnB = TableB.Field
}
into GJ
from sub in GJ.DefaultIfEmpty()
select new
{
Column1 = TableA.Field
Column2 = TableA.Field
Column3 = sub == null ? TableA.Field
sub.Table.TableName.ToUpper().Contains("Operation to perform") ? Convert.ToString
(Convert.ToDecimal(TableA.Field
Convert.ToDecimal(sub.Field
};
dtJoinedTable = resultQuery.ExtCopyToDataTable();
return dtJoinedTable;
}