I am using MVC5 + Ef6 code first with ASP.Net Identity 1.0 and wish to have the tables created in a custom schema. i.e. a schema that is not the dbo schema.
I revers
Sorry my english, i use google translator.
Some steps indicated by Prisioner ZERO are not necessary. The indications provided are based on the standard template with individual user accounts security.
First we must verify that our project is clean (insert commands in Package Management Console):
Drop-Database
Remove-Migration
Now that our project is clean, we must modify the ApplicationDbContext
class. We must overwrite the method OnModelCreating
to indicate the scheme to which each of the tables generated by ASP.NET Identity will belong. The following link shows the entities used to map each of the tables as well as information about custom builders and options to change the data type of the primary key of each table: Identity Model Customization.
public class ApplicationDbContext : IdentityDbContext {
public ApplicationDbContext(DbContextOptions options) : base(options) { }
protected override void OnModelCreating(ModelBuilder builder) {
base.OnModelCreating(builder);
builder.Entity().ToTable("AspNetUsers", "myschema");
builder.Entity().ToTable("AspNetRoles", "myschema");
builder.Entity().ToTable("AspNetUserClaims", "myschema");
builder.Entity().ToTable("AspNetUserRoles", "myschema");
builder.Entity().ToTable("AspNetUserLogins", "myschema");
builder.Entity().ToTable("AspNetRoleClaims", "myschema");
builder.Entity().ToTable("AspNetUserTokens", "myschema");
}
}
Now we only have to generate our migration. For this in the Package Management Console enter the following command (optionally you can indicate the output route with the -OutputDir
parameter):
Add-Migration InitialSchemaIdentity -OutputDir Data\Migrations
Then we apply the changes in our database with the command:
Update-Database