I'm setting up a new project using asp.net 5 and MVC 6, but I want to use Entity Framework 6 due to the missing features in EF 7.
I setup EF 6.1.3 and that is working.
Identity 3.0 depends on EF 7 so I have removed that and referenced in Identity 2.2
but I'm not sure where to go from here.
I'm not sure how this will be handled in the final release of ASP.NET 5, but in the case of ASP.NET 5 RC1 we have the following:
Firstly, you should go with Identity 3.0, as there is no way to use Identity 2.x in MVC 6 as far as I know.
Secondly, to make Identity 3.0 work with EF6, you need to implementation your own "EF6-friendly" versions of all classes under Microsoft.AspNet.Identity.EntityFramework namespace (the code is available here- https://github.com/aspnet/Identity/tree/3.0.0-rc1/src/Microsoft.AspNet.Identity.EntityFramework), as original classes are meant to work with EF7 only:
- IdentityDbContext
- RoleStore
- UserStore
- IdentityRole
- IdentityRoleClaim
- IdentityUser
- IdentityUserClaim
- IdentityUserLogin
- IdentityUserRole
Your implementations should utilize EF6 instead of EF7. The process is pretty straightforward, but if you want to save time, I have shared my implementation here:
https://github.com/EntrypointSoft/AspNet.Identity.EntityFramework6
This comes in a few parts.
- You can use
Microsoft.AspNet.Identity
3.0.0, but you will need to make your own UserStore
and RoleStore
. Personally, I copied the source of UserStore.cs and RoleStore.cs and made the tweaks necessary to use my EF6 User and Role classes. They have some additional features not used by default in EF6, such as normalizing usernames, email addresses, and role names that you'll need to support (or work around), but the interfaces only require POCOs, so you will be good there.
- Follow the Identity Sample MVC project, but with your own Stores specified in your Startup file:
services.AddIdentity<MyEf6User, MyEf6Role>()
.AddRoleStore<MyEf6RoleStore>()
.AddUserStore<MyEf6UserStore>();
- Be very aware that the Microsoft.AspNet.Identity (and all of asp.net 5) is still a work-in-progress, and things such as the bearer token are largely undocumented, and the Identity 3 does have a bit more set up than Identity 2.x; it will require some tweaking and will change for CTP 7 and other future releases.
EDIT for 1.0.0: Migrator.EF6 now supports 1.0.0.
EDIT for RC2: Migrator.EF6 now supports RC2.
The best course of action would be to port Identity's EF7 provider to work with EF6.
For an already done port check this out for Identity 3.0 + EF6 working under Asp.Net Core (5): MR.AspNet.Identity.EntityFramework6.
If you furthermore need EF6 migrations check my other answer here.
Here's a tiny wrapper that ports the ASP.NET EntityFrameowork 6 to ASP.NET Core Identity, in a single small file.
What it does, it wraps the existing UserStore
for EF6 in the new agnostic ASP.NET Core IUserStore<TUser>
.
Support for TKey
made easy.