[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

Linq to SQL query

Hello, could someone help me with the below.

I would like to select all records in the email table when it exists in the customer and preferences table (left outer join?). This must return distinct records and in the form of list(of Emails).

Dim q = From e In db.Emails
                 Join c In db.Customers On e.email Equals c.EmailAddress
                 Join p In db.Preferences On c.CustID Equals c.CustID
                 Where p.condition = True
                 
                 'where do I go from here? Then the list should be returned.

dim emaillist as new list(of Emails)
emailliist = q.tolist

return emaillist

Open in new window


Thanks!
0
badpilot
Asked:
badpilot
1 Solution
 
käµfm³d 👽Commented:
If I understand correctly, the default in Linq is an inner join, so you should implicitly get the rows that exist in all three tables if you join them all up. As for the distinct part, try this mod:
Dim q = From e In db.Emails
                 Join c In db.Customers On e.email Equals c.EmailAddress
                 Join p In db.Preferences On c.CustID Equals c.CustID
                 Where p.condition = True
                 
return q.Distinct().ToList()

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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