Msmaldi.AspNetCore.GuIdentity.EntityFrameworkCore

ASP.NET Core Identity by default uses string as primary key, using GuIdentity you will have guid as a primary key.


Keywords
aspnetcore, entityframeworkcore, identity, membership, guid
License
Other
Install
Install-Package Msmaldi.AspNetCore.GuIdentity.EntityFrameworkCore -Version 2.0.0

Documentation

ASP.NET Core GuIdentity

ASP.NET Core Identity by default uses string as primary key, using GuIdentity you will have guid as a primary key.

Usage

Based in project generated by dotnet new mvc --auth Individual

  1. Run in Package Manager Console:

    dotnet add package Msmaldi.AspNetCore.GuIdentity.EntityFrameworkCore --version 2.0.1

  2. Create a file User.cs add like:

    using Msmaldi.AspNetCore.GuIdentity;
    
    namespace GuIdentitySample.Mvc.Models
    {
    	public class User : GuIdentityUser
    	{        
    	}
    }
  3. In file ApplicationDbContext.cs add and change:

    using Msmaldi.AspNetCore.GuIdentity.EntityFrameworkCore;
    public class ApplicationDbContext : GuIdentityDbContext<User>
  4. In file Startup.cs add and change:

    using Msmaldi.AspNetCore.GuIdentity;
    services.AddDefaultIdentity<User>()
    		.AddEntityFrameworkStores<ApplicationDbContext>();

    or if you need use GuIdentityRole and RoleManager

    services.AddIdentity<User, GuIdentityRole>()
    		.AddEntityFrameworkStores<ApplicationDbContext>()
    		.AddDefaultTokenProviders();
  5. In file /Views/Shared/_LoginPartial.cshtml:

    @inject SignInManager<User> SignInManager
    @inject UserManager<User> UserManager
  6. Delete app.db:

    rm app.db

  7. Delete folder:

    rm -r ./Data/Migrations

  8. Run:

    dotnet ef migrations add CreateGuIdentityInitialSchema -o ./Data/Migrations
    
    dotnet ef database update
    
    dotnet run