1
votes

I'm open to suggestions but the only approach I've found to get Identity to work with minimal effort was to have a migration setup as such:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
  modelBuilder.Entity<IdentityUser>().HasKey(l => l.Id).ToTable("AspNetUsers");
  modelBuilder.Entity<IdentityUserLogin>().HasKey<string>(l => l.UserId).ToTable("AspNetUserLogins");
  modelBuilder.Entity<IdentityRole>().HasKey<string>(r => r.Id).ToTable("AspNetRoles");
  modelBuilder.Entity<IdentityUserRole>().HasKey(r => new { r.RoleId, r.UserId }).ToTable("AspNetUserRoles");
  modelBuilder.Entity<IdentityUserClaim>().HasKey(r => new { r.Id }).ToTable("AspNetUserClaims");}

After I seeded the tables with user data I was then able to fire up my MVC5 web app and login as with various accounts. I was also able to register new users and update existing accounts. Everything seems to work fine.

Are there long term negative effects to what I've done and/or do you have a cleaner but uncluttered approach to get Identity 2.0 working with MVC5?

EDIT: Context:I'm migrating data from several databases that have a home-grown account table and security so I'm creating a console app that culls the account tables from three db's in order to create the Identity-based accounts in a console app to seed all the historical data. So the above code resides in the console app, not the mvc5 project. Once the historical data is seeded, including the Identity tables, I have a separate solution hosting a mvc5 web project that utilizes the new schema.

1
No, but a more interesting question is why you needed to do this in the first place. None of this configuration should be required, so that fact that you added and then it worked might be glossing over a more serious problem.Chris Pratt
added context to question.JQII

1 Answers

0
votes

I have read through numerous post on the excellent overviews at typecast http://typecastexception.com/post/2014/04/20/ASPNET-MVC-and-Identity-20-Understanding-the-Basics.aspx and on asp.net and Scott Gu's blog but I just can't find anything as easy or matter of fact for what I'm needing.