问题
I have 2 datatables of identical structure, and I need to find all records that appear on the first, but not on the second. What makes it more complicated is that the matching needs to be on 3 columns instead of one.
Background - I'm writing a replication process where rows of data arrive in an XML transaction and they need to be matched against the 'host' database to find out if there are any items that need to be added. The basic algorithm is as follows:
- Load in transaction dataset containing several datatables
- Create a new datatable and populate with the 'host' entries from the local database
- Run a match between them to find out which are the 'new' records
- Iterate through said 'new' records and create the objects in the database.
I've seen many examples of LEFT JOIN in LINQ but I can't seem to find anything that specifically meets my needs. It would be easy if the tables were joined on one column, but unfortunately this is not the case....
Any help would be appreciated.
Thanks,
Tim
回答1:
See Microsoft's 101 LINQ Samples. There is a LEFT OUTER JOIN example that should help you out.
来源:https://stackoverflow.com/questions/6658471/linq-left-joining-like-tables