Solved

Linq to SQL query

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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…
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.
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…

930 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

19 Experts available now in Live!

Get 1:1 Help Now