Wednesday, 9 April 2014

Altering the schema name of ASP.NET Identity tables

I like keeping my database schema as clean and readable as possible, and one of the things I do is use a schema name to group related functionality.

I’ve been doing a fair bit of work with ASP.NET Identity recently, and one of the things was to add the generated tables for identity into their own schema. Moreover, I also wanted to change the name of the tables. This is a snap using Code First – all you need to do (in your IdentityDbContext derived class) is the following…


    modelBuilder.Entity<DbUser>().ToTable("Users", "AUTH");
    modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles", "AUTH");
    modelBuilder.Entity<IdentityUserLogin>().ToTable("ExternalLogins", "AUTH");
    modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims", "AUTH");
    modelBuilder.Entity<IdentityRole>().ToTable("Roles", "AUTH");

Make sure you call the base class OnModelCreating method before including these changes. With that you’ll get a nice set of tables inside SQL server…


I realise that this will mean that I need to be careful when installing a new version of ASP.NET Identity (to ensure that the override still works), but I’d rather pay that price and have a ‘clean’ schema.


Kerry Schultz said...

Thanks for this tip, I’m sure everyone will keep it in mind. Please post some information about ASP.NET and how you’ve been using it. I’d really appreciate it.

TLM-Greg said...

I tried this and it does create the tables with the right schema and I am able to register a user. However, I cannot login to my application anymore because UserManager.FindAsync cannot find the user. Any thoughts on why this would stop working? Is there another code change that I need to make?

TLM-Greg said...

Nevermind...I figured it out. Had to pass the username instead of the email address. All is working!

Oliver Maurice said...

You should definitely visit this blog for some information on how to write an essay. This will save your life in the future so do it as soon as possible.

norhan said...

غسيل خزانات بمكة افضل شركة غسيل خزانات بمكة
غسيل خزانات بجدة افضل شركة غسيل خزانات بجدة
غسيل خزانات بالدمام افضل شركة غسيل خزانات بالدمام

ahmed5987 said...

توثيق الحادث الأصلي
أول شيء ستحتاج لإظهار المشتري المحتمل هو توثيق ما حدث. سيشمل ذلك نسخة من تقرير التفتيش أو النتائج التي توصل إليها المفتش ، والتي تبين أن لديك النمل الأبيض. ستحتاج بعد ذلك إلى إظهار وثائق العلاج التي تلقاها منزلك.شركة النجوم لمكافحة الحشرات
شركة مكافحة الصراصير بالرياض
شركة مكافحة فئران بالرياض
شركة مكافحة النمل الابيض بالرياض

Sankar said...

I have read your blog its very attractive and impressive. I like it your blog.
Final Year Projects for CSE in Dot Net

.Net Training in Chennai

Final Year Project Centers in Chennai

Dot Net Training in Chennai

noor said...

الرائد افضل شركة تنظيف و غسيل خزانات بالمدينة المنورة تنظيف خزانات بالمدينة المنورة وتقوم اياب تقيمها بالاشعه الفوق البنفسجية

تنظيف خزانات

William said...

Such an Informative post. I really like your blog.Thanks for sharing this. Basically I work with the web designers in logoistic and our aim is to design your dream website. Thanks again!

Angel17 said...

Such a nice read. I enjoy reading this post! dumpster for rent near me