linq下 多条件 on后面多条件 左连接

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
                              };

自己记录下 请大神指导优化或者同行斧正!


  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值