Generation of ID in Entity Framework’s IdentityUser

This is a personal reminder that default IdentityUser and its friends (like IdentityRole) generate the ID value in its constructor. These classes extend the behavior of the generic classes (IdentityUser implements IdentityUser<TKey, …> with IdentityUser<string, …>). If you happen to use your own class that inherits from them, you’ll be responsible for generating that ID. Otherwise, you’ll get an error like the following: System.Data.SqlClient.SqlException: Cannot insert the value NULL into column ‘Id’ table ‘dbo.AspNetUsers’; column does not allow nulls. INSERT fails. The statement has been terminated. IdentityUser implementation IdentityUser: Microsoft Docs | Code at Github (aspnet/Identity) IdentityUser<TKey, TLogin, TRole, TClaim> : Microsoft Docs | Code at Github (aspnet/Identity) IdentityRole implementation IdentityRole:… Read More

Continue Reading