Hello i have a problem joining tables when i have null values in a record.
There are 2 dataTables:
- Workers: (workerID, workerName, workerAdress)
- Transactions: (transactionID, transactioinValue, worker1, worker2), where worker 2 is optional so it can contain null values.
So i started code like this:
var record = from transaction in dtTransactions.AsEnumerable()
join worker1 in dtWorkers.AsEnumerable() on (int)transactions["worker1"] equals (int)worker1["workerID"]
join worker2 in dtWorkers.AsEnumerable() on (int)transactions["worker2"] equals (int)worker2["workerID"]
select new
{
ID = (int)transactions["transactionID"],
Name1= worker1["workerName"],
Name2= worker2["workerName"]
};
So it all works fine if worker2 isn’t null, but when i have a null value it could not be joined. Can someone help me with this problem, i would like to have a result record without a worker2 name if it’s null in dataTable.
Is it possible?
you need to do a left join like this;
Secondly, is there any reason why you’re not specifying the object properties like this;
Note the removal of the square brackets