使用Joiner表从3个表中查询Linq

时间:2009-11-06 02:11:40

标签: c# linq

我有3个表,Customer,Surfboards和CustomerSurfboards。 CustomerSurfboards是Joiner表。

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

我想选择客户IsActive = true

的所有冲浪板

我需要使用C#

在Linq中执行此操作

1 个答案:

答案 0 :(得分:4)

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;