1

I am creating an api for GET users by id.

But below error occurs.

'IQueryable<ApplicationUser>' does not contain a definition for 'FindAsync' and no accessible extension method 'FindAsync' accepting a first argument of type 'IQueryable<ApplicationUser>' could be found (are you missing a using directive or an assembly reference?)

UsersController.cs

using System.Threading.Tasks;
using fublight_server.Authentication;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;

namespace fublight_server.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UsersController : Controller
    {
        private readonly UserManager<ApplicationUser> _userManager;
        private readonly IConfiguration _configuration;

        public UsersController(IConfiguration configuration, UserManager<ApplicationUser> userManager)
        {
            _userManager = userManager;
            _configuration = configuration;
        }

        [HttpGet]
        public async Task<IActionResult> GetUsers()
        {
            //This should be the list of users
            var users = await _userManager.Users.ToListAsync();
            return Json(users);
        }

        [HttpGet("{id}")]
        public async Task<ActionResult<ApplicationUser>> GetUsersById(int id)
        {
            //This should be the list of users
            return await _userManager.Users.FindAsync(id); <-------------this line shows error
        }

    }

}
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
CCCC
  • 5,665
  • 4
  • 41
  • 88

0 Answers0