I have an existing DB context that worked well so far with EF configuration as below
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Configure Code First to ignore PluralizingTableName convention
// If you keep this convention then the generated tables will have pluralized names.
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
modelBuilder.Conventions.Remove<StoreGeneratedIdentityKeyConvention>();
}
I followed an MSDN article to extend the Identity model provided by MVC to link to a person in my existing DB Context.
App User
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> 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 virtual Person LinkedPerson { get; set; }//My reference to existing person definition
}
Context
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
public DbSet<Person> People { get; set; }
}
The app works as long as I dont use the register or login function. However once I have registered as an user all my models are now duplicated, one as singular the other as a pluralized form of that.
Where could I tell the MVC identity framework not to recreate pluralized tables and use the existing (Singular) db objects?