Search code examples
c#.netasp.net-identityvisual-studio-2019vs-web-application-project

Creating new tables and properties with Identity on Visual Studio


I'm trying to create new tables and relationships between the default Identity tables and mine but when I try to log in using the method "SignInManager.PasswordSignInAsync" which is by default on AccountController I get the errors listed below:

  • Invalid Column Name UserId
  • Invalid Column Name UserId
  • Invalid Column Name RoleId

What I did for creating the Identity context is checking the option on project startup, and then for creating the extra properties on the AspNetUser table I do this:

public class ApplicationUser : IdentityUser
{

    #region

    public DateTime LastLoginDateTime { get; set; }

    public string Name { get; set; }

    public string Surnames { get; set; }

    public string DNI { get; set; }

    public string ProfileImageSource { get; set; }

    #endregion


    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
    {
        // Tenga en cuenta que el valor de authenticationType debe coincidir con el definido en CookieAuthenticationOptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Agregar aquí notificaciones personalizadas de usuario
        return userIdentity;
    }
}

Then I use Enable-Migrations and Update-Database.

Until here everything works fine, but when I add new tables and relationships using another project inside the same solution (just for not mixing context which I think is bad) with entity framework and then update database I got the problem mentioned above.

When registering new users works fine but when the method "SignInManager.PasswordSignInAsync" is called the program crashes.

I don't know what I'm doing wrong guess someone can help me.


Solution

  • I just solved the problem.

    I don't know Why but if I create the database from 0 in SQL Server instead Visual Studio EDMX editor it works perfect.

    If you are tring to solve the same problem as me make the changes on SQL Server directly.