0

I am trying to make a login for a web app. The database was already existing so i used the instructions here to customize the table upon which the login would be performed. There were an error or two that i managed to fix(?) and now i am stuck in this and i really cant understand where it comes from. My context is this

public class ApplicationDbContext : IdentityDbContext<TblAdmin>
{
    public ApplicationDbContext()
        : base("TelecomConnection", throwIfV1Schema: false)
    {
        Database.SetInitializer<ApplicationDbContext>(null);
    }
    public DbSet<TblAdmin> TblAdmins { get; set; }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<TblAdmin>().ToTable("tblAdmins");
    }
}

The most relevant question is this which doesn't help me. The point when the problem occurs is when the user is providing the credentials for login and at that moment the compiler is stopping in this line

 var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe,shouldLockout:false);

the whole method in which this exists, is this:

 public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
    {
        if (!ModelState.IsValid)
        {
            return View(model);
        }

        // This doesn't count login failures towards account lockout
        // To enable password failures to trigger account lockout, change to shouldLockout: true

        var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe,shouldLockout:false);
        switch (result)
        {
            case SignInStatus.Success:
                return RedirectToLocal(returnUrl);
            case SignInStatus.LockedOut:
                return View("Lockout");
            case SignInStatus.RequiresVerification:
                return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            case SignInStatus.Failure:
                ModelState.AddModelError("", "Wrong Password.");
                return View(model);
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return View(model);
        }
    }

I tried and searched the whole project and couldn't even find the world "Users". Anyone can tell me how to fix this?

Community
  • 1
  • 1
lefteris
  • 13
  • 5

1 Answers1

0

IdentityDbContext<TUser> already implements a DbSet for TUser:

public IDbSet<TUser> Users { get; set; }

Since TUser here is TblAdmin (IdentityDbContext<TblAdmin>), when you add the following:

public DbSet<TblAdmin> TblAdmins { get; set; }

TblAdmin is now tracked by two DbSets.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • Thank you Chris for the answer. Is it possible to suppress(sorry for the word english is not my native language) IdentityDbContext from implementing its DbSet? I need mine in order to use other table (not AspNetUsers) for login( and this is the solution that i found for doing that). – lefteris Sep 25 '15 at 13:40
  • No. There's no way to do that. However, you don't need your own `DbSet` to accomplish what you're looking for, just add `[Table("TblAdmins")]` to your class or use fluent config to set the table name you want. – Chris Pratt Sep 25 '15 at 14:39