We're a place where coders share, stay up-to-date and grow their careers.
I like LINQ syntax, but I think it's not really necessary here. I'd write it as:
private User GetUserByToken(string tokenBody) { var token = _context.Tokens.SingleOrDefault(t => t.Body == tokenBody); if (token == null) return null; var user = _context.Users.SingleOrDefault(u => u.Id == token.UserId); return user; }
Of course, this is a subjective matter, so any approach is OK if the team is fine with it.
I like LINQ syntax, but I think it's not really necessary here. I'd write it as:
Of course, this is a subjective matter, so any approach is OK if the team is fine with it.