Solved

LinqToSQL Joins

Posted on 2014-03-10
6
113 Views
Last Modified: 2016-02-10
I'm struggeling with Linq using a single join, but what to do when you have a to use LinqToSQL to join a base entity with many lookups ?

Appointment

Id
ContractId
CustomerId
LocationId
TaskId
EngineerId
0
Comment
Question by:Dodsworth
  • 4
  • 2
6 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39918682
I am not sure of the question you are asking can you be a little bit more descriptive.
0
 
LVL 1

Author Comment

by:Dodsworth
ID: 39919894
An Appointment from a user perspective might read...

id                    2132
Contract        West Coast
Customer      Mr Simon D Jenkins              
Location        249a Hatton Street, Newtown, York, YO23 8YE
Task               Install new alarm system
Engineer       Mr John Reed

Yet the Appointment table is structured as in my initial post, where each column with an Id suffix joins with a related table that holds the user readable data. eg. Appointment.CustomerId links to Customer.CustomerId where Customer has .CustomerId, .Saluation, .Forname, .Initial, .Surname etc.
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39920347
Hi Dodsworth;

See if this gives you what you are looking for.

Dim db = New DataContext()

Dim results = From a In db.Appointment _
              Join c In db.Customer On a.CustomerId Equals c.CustomerId _
              Select a, c 

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Author Comment

by:Dodsworth
ID: 39920534
Do I just tag the other joins on like..
Dim db = New DataContext()

Dim results = From a In db.Appointment _
              Join c In db.Customer On a.CustomerId Equals c.CustomerId _
              Join t In db.Task On a.TaskId Equals t.TaskId _
Select a, c, t  

Open in new window


?
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39920544
As long as a.TaskId is a column in Appointment and t.TaskId is a column in Task then yes.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39925418
Has that answered your question?
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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