I customized Microsoft.AspNet.Identity classes. The code is below:
public class ApplicationUserRole : IdentityUserRole<Guid>
{
}
public class ApplicationUserClaim : IdentityUserClaim<Guid>
{
}
public class ApplicationUserLogin : IdentityUserLogin<Guid>
{
}
public class ApplicationRole : IdentityRole<Guid, ApplicationUserRole>
{
public ApplicationRole() { }
public ApplicationRole(string name) { Name = name; }
}
public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationRole, Guid, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
public ApplicationUserStore(ApplicationDbContext context)
: base(context)
{
}
}
public class ApplicationRoleStore : RoleStore<ApplicationRole, Guid, ApplicationUserRole>
{
public ApplicationRoleStore(ApplicationDbContext context)
: base(context)
{
}
}
public class ApplicationUser : IdentityUser<Guid, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, Guid, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>().HasKey(l => l.Id).ToTable("tbl_Users", "membership");
modelBuilder.Entity<ApplicationRole>().HasKey(l => l.Id).ToTable("tbl_Roles", "membership");
modelBuilder.Entity<ApplicationUserClaim>().HasKey(l => l.Id).ToTable("tbl_UserClaims", "membership");
modelBuilder.Entity<ApplicationUserLogin>().HasKey(l => new { l.UserId, l.ProviderKey, l.LoginProvider }).ToTable("tbl_UserLogins", "membership");
modelBuilder.Entity<ApplicationUserRole>().HasKey(l => new { l.RoleId, l.UserId }).ToTable("tbl_UserRoles", "membership");
}
When I run it first, everything works, creating tables in SQL Server; but If I add property (example public string FirstName {get; set;}) in class ApplicationUser and run it to make changes in database, throws error:
The model backing the 'ApplicationDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database
I know that I must enable migrations, but is there any way to do it without migrations, because it create own folder(Configuration) and generate class in it?