• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 734
  • Last Modified:

LINQ to SQL with multiple tables and multiple column join

I have three datatables


dt1 has three columns ID, Date, Price
dt2 has two columns ID, CurrencyCode,
dt3 has three columns CurrencyCode , Date , Rate

I need to join the three tables

                                                      from dataRows1 in dt1.AsEnumerable()
                                     join dataRows2 in dt2.AsEnumerable()
                                     on dataRows1["ID"] equals dataRows2["ID"]                                
                                     join dataRows3 in dt3.AsEnumerable()
                                                       on dataRows2["CurrencyCode"]  equals dataRows3["CurrencyCode"] AND dataRows1["Date"] equals dataRows1["Date"]
1 Solution
käµfm³d 👽Commented:
The last bit of your query needs to introduce anonymous objects. You do this any time you need a mult-column join. For example:

join dataRows3 in dt3.AsEnumerable() on
new { CurrencyCode = dataRows2["CurrencyCode"], Date = dataRows1["Date"] } equals
new { CurrencyCode = dataRows3["CurrencyCode"], Date = dataRows3["Date"] }

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now