The stock asp.net mvc 5 application creates the application users, aka identity users in a separate context, named a file called "IdentityModels.cs" - it looks like this
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
}
I am attempting to put the Application users in a regular data context, i.e. something like this
public class BlogProphetContext : DbContext
{
public DbSet<ApplicationUser> ApplicationUsers { get; set; }
public DbSet<Answer> Answers { get; set; }
public DbSet<Question> Questions { get; set; }
public DbSet<Tag> Tags { get; set; }
}
However, every time I do that I get the following error every time I try to create an account
The UserId field is required
In the AccountController.cs when I attempt to execure the following line of code
result = await UserManager.AddLoginAsync(user.Id, info.Login);
I get the feeling my approach is wrong, and that I cannot have the ApplicationUsers in the main data context file without some sort of external chicanery - does anyone know of some way to do this? All of the files are up to date.
Ensure that your ApplicationUser class inherits from IdentityUser.
Then you need to configure your context so that it maps all the ASP.NET Identity classes correctly. These are:
Details of this is a bit too complicated to post here, but I have made a sample project that works with the release version of ASP.NET Identity. You can see it here: https://github.com/onybo/Asp.Net-Identity-sample-app/tree/master/CustomUser
In this case, if you dont want your ApplicationUser to be associated with asp.net Identity the easiest thing would be to just remove the inheritance from the applicationUser class.
Go from ApplicationUser : IdentityUser to just ApplicationUser, then in that class just create an Id property.
You wont have to use IdentityDBContext then.
Of course you will have to totally rewrite AccountController, or get rid of it. You cant use UserManager anyways as thats linked to IdentityUser
Then obviously make sure you add your migration/update database if you are working with EF.
If you do want to keep the account controller as is and keep IdentityDbContext but add other entities then thats easy, just do this:
This was a bit too easy - it turns out that all you have to do it remove the
when you call the context and everything turns out like you might expect (i.e. the MVC assumptions and the developers assumptions (in this case, mine) sync.
Here is is working properly
I am not sure if this will help you or if i fully understand your questions...but if you want try use your own "model" then change:
I do not know how much more than this you can configure or if this will really change the context.