您好我试图为三个表实现内连接 我从两个表开始,它给了我适当的结果。
但我不知道如何实现三个表的连接? 有人可以帮忙吗?
这是我想在EF中执行的select语句:
SELECT
capt_ar AS VehicleState,
cont_name,
vehl_drivername,
vehl_name,
vehl_entrancedate,
vehl_customsdec,
cont_rampid
FROM Container
INNER JOIN
Vehicle ON Container.cont_vehicleid = Vehicle.vehl_VehicleID
INNER JOIN
Custom_Captions ON Vehicle.vehl_state = Custom_Captions.Capt_Code
WHERE capt_family = 'vehl_state'
AND vehl_Deleted IS NULL AND cont_Deleted IS NULL
AND vehl_ClearanceCompany = 471
更新:SQL Server中的查询结果
更新:这是我试图做的但没有输出
var result = (from cont in db.Containers
join veh in db.Vehicles on cont.cont_vehicleid equals veh.vehl_VehicleID
join cap in db.Custom_Captions on veh.vehl_state equals cap.Capt_Code
where cap.Capt_Family == "vehl_state && veh.vehl_Deleted == null && cont.cont_Deleted == null && veh.vehl_ClearanceCompany =="+p.pusr_CompanyId
select new { cap.Capt_AR, cont.cont_Name, veh.vehl_drivername, veh.vehl_Name, veh.vehl_entrancedate, veh.vehl_customsdec, cont.cont_rampid }
答案 0 :(得分:0)
var query = (from con in db.Containers
join v in db.Vehicles on con.cont_vehicleid equals v.vehl_VehicleID
join cust in db.Custom_Captions on v.vehl_state equals cust.Capt_Code
where cust.Capt_Family== "vehl_state" && v.vehl_Deleted==null && con.cont_Deleted==null && v.vehl_ClearanceCompany==p.pusr_CompanyId
select new
{
cont_name=con.cont_Name,
vehl_Name=v.vehl_Name,
VehicleState=v.vehl_state,
vehl_drivername=v.vehl_drivername,
vehl_entrancedate=v.vehl_entrancedate,
vehl_customsdec=v.vehl_customsdec,
cont_rampid=v.vehl_rampid
}
).ToList();