Having trouble with identity users in asp.net core 3 web application, receiving 'invalid object name Aspnetusers' error

247 Views Asked by At

Good Day. I am suffering a problem with asp.net identity. I am getting error at this line:

var user = await _userManager.FindByEmailAsync(Input.Email);

the error is : (Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid object name 'AspNetUsers'. ) For your kind information, I have added a model ApplicationUser

public class ApplicationUser : IdentityUser
    {
        public string UserID { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string PhoneNo { get; set; }

        //============Linked Table==================
        [Display(Name = "ব্যাবহারকারীর ধরণ")]
        [ForeignKey("UserType")]
        public int UserTypeId { get; set; }
        public UserType UserType { get; set; }

        [Display(Name = "ব্যাবহারকারীর শাখা")]
        [ForeignKey("Department")]
        public int DepartmentId { get; set; }
        public Department Department { get; set; }

        //============Image Url====================

        [Display(Name = "ব্যাবহার কারীর ছবি")]
        public string UserImageURL { get; set; }
    }

here is my application db context:

public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options)
        {
        }

here is my startup.cs file

services.AddIdentity<ApplicationUser, IdentityRole>()
                    // adds UserStore and RoleStore for Usermanager and RoleManager
                    .AddEntityFrameworkStores<ApplicationDbContext>()
                    .AddDefaultUI()
                    // adds a provider that generates unique keys and hashes for things like forgot password links, phone verification etc
                    .AddDefaultTokenProviders();

for register.cs and login.cs

private readonly UserManager<ApplicationUser> _userManager;
        private readonly SignInManager<ApplicationUser> _signInManager;
        private readonly ILogger<LoginModel> _logger;
        private readonly IEmailSender _emailSender;

        public LoginModel(SignInManager<ApplicationUser> signInManager,
            ILogger<LoginModel> logger,
            UserManager<ApplicationUser> userManager,
            IEmailSender emailSender)
        {
            _userManager = userManager;
            _signInManager = signInManager;
            _emailSender = emailSender;
            _logger = logger;
        }

can any body suggest me what is the problem... I am stuck on this line

var user = await _userManager.FindByEmailAsync(Input.Email);

thanks in advance Moseur

0

There are 0 best solutions below