linq下 多条件 on后面多条件
1、左连接的实现主要是基于 join 后加 into 变量1
from 变量 in 变量1.DefaultIfEmpty()
2、这里还有一个多条件的例子:
new{ColorCode=productColor.ColorCode,PTCode="ProductColors" } equals new {ColorCode=parameter.PValue,PTCode=parameter.PTCode}
匿名类里放多个值equals 来实现多条件联合查询
下面是多个表联合左查询 多条件实例
var queryMatial = from palnOrder in _substationPlanOrderItemRepository.Entities
join productInfo in _productInfoRepository.Entities on palnOrder.ProductCode equals productInfo.ProductCode into left1
from productInfo in left1.DefaultIfEmpty()
join brandInfo in _brandInfoRepository.Entities on productInfo.BrandCode equals brandInfo.BrandCode into left2
from brandInfo in left2.DefaultIfEmpty()
join productColor in _productColorRepository.Entities on productInfo.ProductCode equals productColor.ProductCode into left3
from productColor in left3.DefaultIfEmpty()
join parameter in _parameterRepository.Entities on new{ColorCode=productColor.ColorCode,PTCode="ProductColors" } equals new {ColorCode=parameter.PValue,PTCode=parameter.PTCode} into left4
from parameter in left4.DefaultIfEmpty()
join productCata in _productCategoryRepository.Entities on productInfo.CategoryCodeMain equals productCata.CategoryCode into left5
from productCata in left5.DefaultIfEmpty()
// where parameter.PTCode == "ProductColors"
select new orderMatialEntity
{
ProductId = productInfo.ProductId,
ProductCode = productInfo.ProductCode,
ProductName = productInfo.ProductName,
BrandCode = productInfo.BrandCode,
BrandName = brandInfo.BrandName,
Model = productInfo.Model,
Specifications = productInfo.Specifications,
Material = productInfo.Material,
Color = parameter.PValue,
Qnty = palnOrder.Qnty.Value,
Remark = palnOrder.Remark,
ProductStatus = palnOrder.ProductStatus,
PurchaseCode = palnOrder.PurchaseCode,
MainCatalogCode = productCata.CategoryCode,
MainCatalogName = productCata.CategoryName
};
自己记录下 请大神指导优化或者同行斧正!