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.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
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.
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.