'Controller Method Get : Get specify attributes from a Class

my question is simple, I´m try to do a controller that pass some attributes of a Model

This is the method:

[HttpGet("getAllUserInfo")]
public async Task<ActionResult<object>> GetAll() {
    var test = await _context.Users.ToListAsync(); //here I have the all Info of all users

    //In the return I want pass some attributes of user, creating a new object (ex: The user have a password but I don´t want to show that)
    return Ok(new { test.getType().Name, test.getType().Mail });
    //this above is the part of the code I don´t understand
    }

Is there any alternative to this scenario or what are the possible ideas to make this possible?

Sorry if there are any spelling mistakes in the title and document, but I think the idea where I have difficulty understanding is there



Solution 1:[1]

Are you just trying to project a list of objects into a new list of different objects? You can do that with .Select(). For example:

return Ok(test.Select(t => new { Name = t.Name, Mail = t.Mail }));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David