I want to use ASP.Net-Identity for user management. For this, I want to extend the IdentityUser
class with a few attributes.
public class AppUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<AppUser> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
public int Settings_ID { get; set; }
public string Position { get; set; }
public string CompanyName { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
[...]
Now, in my data context
, I want to create just one table for this user model:
public class AntContext : IdentityDbContext<AppUser>
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer<AntContext>(null);
modelBuilder.Entity<AppUser>().ToTable("AppUsers");
base.OnModelCreating(modelBuilder);
}
public override IDbSet<AppUser> Users { get; set; }
[...]
However, when trying to update-database
, I receive the error:
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_dbo.AppUsers_dbo.AspNetUsers_Id". The conflict occurred in database "C:\USERS\NEUMA\SOURCE\REPOS\MYANTON\MYANTON\APP_DATA\ASPNETDB.MDF", table "dbo.AspNetUsers", column 'Id'.
I understand that AspNetUsers
is a table from IdentityUser
, but how do I create only one table so that there are no conflicts?
How do I properly extend the IdentityUser
class and use it in my data context?