I am trying to join two datatables using linq
var invoices420 = dt420_.AsEnumerable();
var invoices430 = dt430_.AsEnumerable();
var query = from inv430 in invoices430
join inv420 in invoices420 on inv430.LinkDoc equals inv420.LinkDoc
orderby inv430.SID
select new
{
LinkDoc = inv430.LinkDoc,
TotalIn = Math.Round(inv430.Credit, 2),
TotalOut = ((inv420 == null) ? 0 : Math.Round(inv420.Debit, 2))
};
Joining does not seems to be a problem, but I am getting an error'System.Data.DataRow' does not contain a definition for 'LinkDoc' and no extension method 'LinkDoc' accepting a first argument of type 'System.Data.DataRow' could be found (are you missing a using directive or an assembly reference?).
What do I have to do to reference a column in DataTable for example inv430.LinkDoc without using inv430.Field("linkdoc")?
If I want to do a group by on result set I am thinking
var q2 = query
.GroupBy(item => item.LinkDoc);
return q2.ToArray();
Problem is that in q2 I dont get all the columns (linkdoc, totalin, totalout).
Original data is
dt420_
Linkdoc Credit
Invoice1 500
Invoice2 100
Invoice3 200
dt430_
LinkDoc Debit
Invoice1 100
Invoice1 100
Invoice2 200
Result would be
LinkDoc TotalIn(Credit) TotalOut(Debit)
Invoice1 500 200
Invoice2 100 200
Invoice3 200 0