Link to home
Start Free TrialLog in
Avatar of dewacorp_alliances
dewacorp_alliancesFlag for Australia

asked on

How to Join for 1 Bridge table with 3 tables in Linq

I have tables association such as (CaseClient is a bridge table):

Cases have many CaseClients (Cases.CaseID = CaseClients.CaseID)
Clients have many CaseClients (Clients.ClientID = CaseClient.ClientID)
ClientTypes have many CaseClients (ClientTypeID.ClientTypeID = CaseClients.ClientTypeID)

How to do a join for 1 Bridge table with 3 tables (above) in Linq? Also, possibly a 'right join' as well?

I am appreciated your comment.

Thanks

Avatar of kaufmed
kaufmed
Flag of United States of America image

I'm having trouble picturing your table relationships from your description (maybe I'm just being dense). I am attaching a linq statement that I believe may be what you are looking for, if not, it may give you an idea of where to start.
var data = from cRow in caseTable.AsEnumerable()
           join clRow in clientTable.AsEnumerable() on cRow["CaseID"] equals clRow["CaseID"]
           join tRow in typeTable.AsEnumerable() on clRow["ClientID"] equals tRow["ClientID"]
           select new
           {
               CaseID = cRow.Field<string>("CaseID"),
               ClientID = clRow.Field<string>("ClientID"),
               ClientTypeID = tRow.Field<string>("ClientTypeID")
           };
 
foreach (var id in data)
{
    listBox1.Items.Add(id.CaseID);
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dewacorp_alliances
dewacorp_alliances
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial