繁体   English   中英

如何在 linq 查询中设置内连接

[英]How to set inner join in linq query

我想在 linq 查询中设置内连接

这是我的代码,

var JoinUsingMS = from emp in _productRepository.Table
   join address in _purchaseReminderRepository.Table
  on new { c1 = emp.VendorId, c2 = emp.Name } equals new { c1 = address.VendorId, c2 = address.Product } into bp_sm
   from c in bp_sm.DefaultIfEmpty()
   where emp.Published == true
   select emp;

从这个查询中,我得到了左连接(通过调试跟踪) 虽然我认为这个查询非常适合内部连接(参考链接As Per This Solution仍然 output 获得左连接

下面更新了内部连接的查询:

var JoinUsingMS = from emp in _productRepository.Table
   join address in _purchaseReminderRepository.Table
   on new { c1 = emp.VendorId, c2 = emp.Name } 
   equals new { c1 = address.VendorId, c2 = address.Product }
   where emp.Published == true
   select emp;

简单的。 删除DefaultIfEmpty行。 这就是创建左连接子句的原因:

var JoinUsingMS = 
    from emp in _productRepository.Table
    join address in _purchaseReminderRepository.Table
      on new { c1 = emp.VendorId, c2 = emp.Name } equals new { c1 = address.VendorId, c2 = address.Product } // into bp_sm
    // from c in bp_sm.DefaultIfEmpty()
    where emp.Published == true
    select emp;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM