Solved

Linq to SQL query

Posted on 2011-03-10
1
202 Views
Last Modified: 2012-05-11
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
Comment
Question by:badpilot
1 Comment
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35096840
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now