LINQ Join with Multiple Conditions in On Clause

前端 未结 4 817
小鲜肉
小鲜肉 2020-11-28 05:25

I\'m trying to implement a query in LINQ that uses a left outer join with multiple conditions in the ON clause.

I\'ll use the example of the following two tables

4条回答
  •  悲&欢浪女
    2020-11-28 05:46

    This works fine for 2 tables. I have 3 tables and on clause has to link 2 conditions from 3 tables. My code:

    from p in _dbContext.Products join pv in _dbContext.ProductVariants on p.ProduktId equals pv.ProduktId join jpr in leftJoinQuery on new { VariantId = pv.Vid, ProductId = p.ProduktId } equals new { VariantId = jpr.Prices.VariantID, ProductId = jpr.Prices.ProduktID } into lj

    But its showing error at this point: join pv in _dbContext.ProductVariants on p.ProduktId equals pv.ProduktId

    Error: The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'.

提交回复
热议问题