连接多个表的列 LINQ

Joining column with multiple tables LINQ

有一个 table 我想加入不同 table 中的不同列。

到目前为止我就是这样做的

var purchData = (from a in db.AppRequest
join e in db.Employee on a.Req_By equals e.Id
join c in db.Company on e.CompanyId equals c.Id
join d in db.Designation on e.DesignId equals d.Id
join l in db.Master_Locations on a.Req_Location equals l.Id
join dep in db.Department on e.DepId equals dep.Id
join p in db.Purchase on a.Id equals p.Req_Id
join pi in db.PurchasingItems on p.Id equals pi.Purchase_Id
join pd in db.PurchasingDetails on p.Id equals pd.Purchase_Id
join pds in db.PurchasingDetailsSup on pd.Id equals pds.PurchasingDetails_Id
join s in db.M_Supplier on pds.Supp_Id equals s.Id
join payMethod in db.Master_PayMethods on s.Pay_Method equals payMethod.Id
join poNo in db.ApprovedPoNumbers on p.Id equals poNo.Purchase_Id
where a.Id == id && pds.IsApproved == true

db.ApprovedPoNumbers table中有purchase_IdSupplier_Id

db.PurchasingDetailsSup中table有purchase_IdSupplier_Id

所以我想知道这里 join poNo in db.ApprovedPoNumbers on p.Id equals poNo.Purchase_Id 行我想加入 db.ApprovedPoNumbers table purchase_Id,Supplier_Iddb.PurchasingDetailsSup table purchase_IdSupplier_Id

您可以通过使用您打算匹配的条件构建两个对象并在它们上使用 equals 运算符来实现:

on new {poNo.purchase_Id, poNo.Supplied_Id} equals new {pds.purchase_Id, pds.Supplier_Id} into details