Solved

Linq to SQL query

Posted on 2011-03-10
1
205 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 75

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

829 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