I have a users table in my database that includes username, encrypted password, email and role id. I would like to pull back a list of all users excluding the password.
Through searching I have found answers for ef 6 and below but nothing that works in ef core.
This is what I have currently:
using (var context = new dbcontext())
{
return context.Users.ToList()
}
I have tried
using (var context = new dbcontext())
{
return context.Users
.Select (u => new
{
Id = u.Id
Username = u.Username
Email = u.Email
}
.ToList()
}
Doing this returns nothing.
I have tried mapping a new entity and class to the table leaving out the password column but nothing gets returned. I think possibly because it's a required field.
Currently I am just converting the response to a new UserSummary class that doesn't have the password property but I'd think there is a way to do this without the password being returned at all.