[英]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.