LINQ to SQL Join issues

前端 未结 3 550
迷失自我
迷失自我 2021-01-05 09:06

I\'m trying to use the following LINQ to SQL in my code:

  (from s in dc.Accounts 
  join purchases in dc.Transactions on s.AccID equals purchases.Account in         


        
3条回答
  •  清酒与你
    2021-01-05 09:59

    This problem often occurs when you are comparing the properties of different types as well. Such as comparing a short to an int, or a string to an int, etc. The names must match, but when your comparison already has equal names and you can't find the issue, check if they are also of the same type.

    from p in DbSet.AsQueryable()
    join t in _dbContext.SomeEntity on new { p.Id, Type = (int)MyEnum.Something }
                                equals new { t.Id, Type = t.EntityType}
    

    In this example, if t.EntityType is short, which is being compared to an integer, it will also give you the message:

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

提交回复
热议问题