Working implementation I have changed the default type of the identityUser to an integer and the rest of the configuration in order to get it to work correctly again.
Startup Configuration
Changed: identityBuilder = new IdentityBuilder(identityBuilder.UserType, typeof(IdentityRole<int>), identityBuilder.Services);
Custom User class
Changed: public class AppUser : IdentityUser<int>
ApplicationDbContext
Changed: public class ApplicationDbContext : IdentityDbContext<AppUser, IdentityRole<int>, int, IdentityUserClaim<int>, IdentityUserRole<int>, IdentityUserLogin<int>,IdentityRoleClaim<int>, IdentityUserToken<int>>
Old Implementation The identityResult variable in the Repository implementation is returning null and throws the following exception:
System.InvalidOperationException: Unable to track an entity of type 'AppUser' because primary key property 'Id' is null
Startup Configuration
var identityBuilder = services.AddIdentityCore<AppUser>(o =>
{
// configure identity options
// Options are intentionally let out
});
identityBuilder = new IdentityBuilder(identityBuilder.UserType, typeof(IdentityRole), identityBuilder.Services);
identityBuilder.AddEntityFrameworkStores<ApplicationDbContext>();
Custom User class
public class AppUser : IdentityUser
{
// Extended Properties
public string FirstName { get; set; }
public string LastName { get; set; }
}
ApplicationDbContext
public class ApplicationDbContext : IdentityDbContext<AppUser>
Repository
public async Task<CreateUserResponse> CreateUser(User user, string password)
{
var appUser = _mapper.Map<AppUser>(user);
var identityResult = await _userManager.CreateAsync(appUser, password);
return new CreateUserResponse(appUser.Id.ToString(), identityResult.Succeeded, identityResult.Succeeded ? null : identityResult.Errors.Select(e => new Error(e.Code, e.Description)));
}