In the new Entity Framework 6.1 beta/pre-release they have included the option to change the datatype of the Id
column that is used within the database. I am looking into how this should be implemented and have come to the following:
public class ApplicationUser : IdentityUser<int, IdentityUserLogin<int>,
IdentityUserRole<int>, IdentityUserClaim<int>>, IObjectState
{
}
public class AuthenticationContext : IdentityDbContext<ApplicationUser, IdentityRole<int, IdentityUserRole<int>>, int, IdentityUserLogin<int>, IdentityUserRole<int>, IdentityUserClaim<int>>
{
public AuthenticationContext()
: base("ConnectionString")
{
}
}
public AccountController() : this(new UserManager<ApplicationUser, int>(new UserStore<ApplicationUser, IdentityRole<int, IdentityUserRole<int>>, int, IdentityUserLogin<int>, IdentityUserRole<int>, IdentityUserClaim<int>>(new AuthenticationContext())))
{
}
public AccountController(UserManager<ApplicationUser, int> userManager)
{
UserManager = userManager;
}
public UserManager<ApplicationUser, int> UserManager { get; private set; }
When running the application (which is the default EF/MVC app) I get the following errors when clicking Register:
An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code Additional information: The type 'Microsoft.AspNet.Identity.EntityFramework.IdentityRole2[System.Int32,Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole1[System.Int32]]' was not mapped. Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation. Verify that the type was defined as a class, is not primitive or generic, and does not inherit from EntityObject.`
Obviously I'm doing something wrong, but I'm unsure what I should adjust to make it work. Any suggestions?
I would try following this example: http://blogs.msdn.com/b/webdev/archive/2013/12/20/announcing-preview-of-microsoft-aspnet-identity-2-0-0-alpha1.aspx under "Make the type of Primary Key be extensible for Users and Roles". The difference is that you create separate classes for each identity model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With