Need help Joining 5 Tables in LinQ

Hi,

I have 5 tables .
Table A with Person ID as Primary Key
Table B with Service ID as Primary key
Table C Service ID as FK
Table D Service ID as FK

Table E Service ID as FK

Now when user search by Service ID I need to join 5 tables to send all data . Is there any option to pass whole raw from particular table without mentioning all fields ?
Vikash pAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gautham JanardhanCommented:
do u mean something like this
var d = from emp in Employee 
             join dep in Department on dep,Id = emp.DepartmentId
             select dep;

Open in new window



here select dep would return all column in department
0
käµfm³d 👽Commented:
What do you mean by "whole raw?"
0
Vikash pAuthor Commented:
Gautam You have joined just two tables I need code how to do this on multiple table.

Kaufmed whole raw means::  i need to return data from 5 tables . 2 tables have 20+ columns and i need all columns value . so don't want to specify each column like TableC.Column1, TableD.Column2 for those tables rather want to return like ( TableC.allcolumns, tableD.AllColums, TableA.Column1, Table2. Column2) from other 3 tables i want to return only 4/5 columns from each table.
0
käµfm³d 👽Commented:
You can expand gauthampj's example to include the remaining tables as:

var query = from a in TableA 
            join b in TableB on a.PersonID equals b.PersonID
            join c in TableC on b.ServiceID equals c.ServiceID
            join d in TableC on b.ServiceID equals d.ServiceID
            join e in TableC on b.ServiceID equals e.ServiceID
            select new
            {
                TableA = a,
                TableB = b,
                TableC = c,
                TableD = d,
                TableE = e
            };
            
foreach (var row in query)
{
    var v1 = row.TableA.PersonID;
    var v2 = row.TableB.ServiceID;
}

Open in new window


But note that there's an extra layer to go through. In the Select part of the query, you are basically selecting the whole row and assigning it to the property name (lines 8 - 12). That means when you actually interrogate the data (lines 15 - 19) you have to include this extra layer (lines 17 & 18).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.