我们正在使用实体框架来获取一些数据。LINQ 查询使用多个连接,如下面的代码所示。我被要求将其更改为 SQL 存储过程,因为它更快。我如何优化这个 LINQ 代码,为什么它很慢?
var brands = (from b in entity.tblBrands
join m in entity.tblMaterials on b.BrandID equals m.BrandID
join bm in entity.tblBranchMaterials on m.MaterialID equals bm.MaterialID
join br in entity.tblBranches on bm.BranchID equals br.BranchID
where br.BranchID == branch.branchId
select new Brand { brandId=b.BrandID, brandName=b.BrandName, SAPBrandId=b.SAPBrandID}).Distinct();
return brands.ToList();