Slee
Slee

Reputation: 28278

Linq query from 3 tables using Joiner table

I have 3 tables, Customer, Surfboards, and CustomerSurfboards. CustomerSurfboards is the Joiner table.

Customer      CustomerSurfBoards    Surfboards   
----------    -------------------   ------------  
CustomerID    CustomerSurfboardID   SurfBoardID
IsActive      CustomerID
              SurfboardID 

I want to select all surfboards where the customer IsActive = true

And I need to do this in Linq using C#

Upvotes: 1

Views: 1348

Answers (1)

jason
jason

Reputation: 241789

var query = from sb in db.Surfboards
            join csb in db.CustomerSurfBoards on sb.SurfBoardID equals csb.SurfBoardID
            join c in db.Customers on csb.CustomerID equals c.CustomerID
            where c.IsActive
            select sb;

Upvotes: 4

Related Questions