简体   繁体   中英

How to set inner join in linq query

I want to set inner join in linq query

Here is my code,

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;

From this query I am getting left join (track by doing debug) . While I think so this query is perfect for inner join (reference link As Per This Solution ) still output getting the left join

Below updated query for the inner joins:

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;

Simple. Remove the DefaultIfEmpty line. That's what creates the left join clause:

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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