Use a filter in an outer join in linq

前端 未结 1 748
夕颜
夕颜 2021-01-19 16:33

I have the following entities:

public class Company
    {
        public string CompanyName { get; set; }
        public int ID { get; set; }
    }

public c         


        
相关标签:
1条回答
  • 2021-01-19 17:17

    You need to either apply the filter before the join:

    join cc in CompanyCurrency.Where(e => e.CompanyId == 1)
    

    or as part of the join

    on new { CurrencyId = c.ID, CompanyId = 1 } equals new { cc.CurrencyId, cc.CompanyId }
    

    For inner joins it doesn't really matter, but for outer join it's important (the same btw applies to SQL queries).

    0 讨论(0)
提交回复
热议问题