You shouldn't use the join keyword, a second "from" is best:
i) you get to use the equality operator;
ii) you can arrange the operands any way you like;
iii) you can add on the DefaultIfEmpty() function on the end to change to a left join and vice versa.
private User GetUserByToken(string token)
{
var user = (from u in _context.Users
from t in _context.Tokens.Where(T => t.UserId == u.Id)
where t.Body == token
select u).SingleOrDefault();
return user;
}
Also, I always use the LINQ format instead of chained functions. Simply because it's more readable.
This is so true. The join was unnecessary 🤔 I was kind of suprised to why the Lambda version I switched to seems shorter, it was because it didn't use a join 😬
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You shouldn't use the join keyword, a second "from" is best:
i) you get to use the equality operator;
ii) you can arrange the operands any way you like;
iii) you can add on the DefaultIfEmpty() function on the end to change to a left join and vice versa.
Also, I always use the LINQ format instead of chained functions. Simply because it's more readable.
This is so true. The join was unnecessary 🤔 I was kind of suprised to why the Lambda version I switched to seems shorter, it was because it didn't use a join 😬