ASP.NET Core Identity by default uses string as primary key, using GuIdentity you will have guid as a primary key.
Based in project generated by dotnet new mvc --auth Individual
-
Run:
dotnet add package Msmaldi.AspNetCore.GuIdentity.EntityFrameworkCore --version 3.0.0
-
Create a file User.cs add like:
using Msmaldi.AspNetCore.GuIdentity; namespace GuIdentitySample.Mvc.Models { public class User : GuIdentityUser { } }
-
In file ApplicationDbContext.cs add and change:
using Msmaldi.AspNetCore.GuIdentity.EntityFrameworkCore;
public class ApplicationDbContext : GuIdentityDbContext<User>
-
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();
-
In file /Views/Shared/_LoginPartial.cshtml:
@inject SignInManager<User> SignInManager @inject UserManager<User> UserManager
-
Delete app.db:
rm app.db
-
Delete folder:
rm -r ./Data/Migrations
-
Run:
dotnet tool install --global dotnet-ef dotnet ef migrations add CreateGuIdentityInitialSchema -o ./Data/Migrations dotnet ef database update dotnet run