I have these extension methods below, 2 from ClaimsPrincipal and one from UserManager, all fetch email.
What is the difference and which one is faster? (i.e. doesn't require as much time to fetch from the database or doesn't fetch from the database at all or do they all fetch from the db?
var email = HttpContext.User.GetUserEmail();
public static string GetUserEmail(this ClaimsPrincipal user) {
return user.FindFirst(ClaimTypes.Email)?.Value;
}
var email = HttpContext.User.RetrieveEmailFromPrincipal();
public static string RetrieveEmailFromPrincipal(this ClaimsPrincipal user) {
return user?.Claims?.FirstOrDefault(x => x.Type == ClaimTypes.Email)?.Value;
}
var ca = await _userManager.Users
.Where(p => p.Id == d)
.Select(p => p.Email)
.FirstOrDefaultAsync();