Linq查询(多条件join on查询)

  1. IList<RDEquipment> list = null;
  2.             list = (from c in gc.GasEquipmentDetail
  3.                     join d in gc.GasCompanyRD on c.ForeignID equals d.ID
  4.                     join e in gc.GasAttachment on new { ID = c.ID, SourceType = Convert.ToInt32(AttachmentSourceType.Equipment) } equals new { ID = (int)e.SourceID, SourceType = (int)e.SourceType } into EquipmentAtt
  5.                     join g in gc.GasDictionary on c.Type equals g.ID
  6.                     from att in EquipmentAtt.DefaultIfEmpty()
  7.                     where g.Category == "RDEquipment"
  8.                     && d.ID == forid
  9.                     && c.IsDeleted == 0
  10.                     select new RDEquipment
  11.                     {
  12.                         EquipmentType = g.Title,
  13.                         EqpID = c.ID,
  14.                         EquipmentName = c.EquipmentName,
  15.                         Quantity = c.Quantity,
  16.                         AttID = att.ID,
  17.                         FileName = att.FileName,
  18.                         FilePath = Gasgoo.Framework.AttachDirFactory.GetAttachPath(AttachmentSourceType.Equipment, att.FilePath)
  19.                     }).ToList<RDEquipment>();
join ... on new { ID = c.ID, SourceType = Convert.ToInt32(AttachmentSourceType.Equipment) } 
equals new { ID = (int)e.SourceID, SourceType = (int)e.SourceType }
相当于sql语句中join ... on c.ID=e.SourceID and sourcetype=e.sourcetype
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值