0

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

s.k.Soni
  • 1,145
  • 1
  • 15
  • 34

2 Answers2

0

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;
Rahul Shukla
  • 576
  • 5
  • 17
0

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;
Jim Wooley
  • 9,920
  • 1
  • 23
  • 43