?
Solved

Linq to SQL query

Posted on 2011-03-10
1
Medium Priority
?
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Suggested Courses

777 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