Reputation: 2009
I have just begun a new project using the ASP .Net Identity 2. It generates a database out of the box for the Identity tables which is fine. My confusion is where do I put my application specific tables? Do I create an entirely separate DbContext & database for them or is it best practice to simply bundle all of the tables into one database together?
Thanks
Upvotes: 1
Views: 109
Reputation: 2085
If you are using asp.net MVC5 identity 2 then ApplicationDbContext already there in IdentityModels.cs .So you can use that.
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("ApplicationDbContext", throwIfV1Schema: false)
{
}
public DbSet<Department> Departments { get; set; }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
Upvotes: 2
Reputation: 5979
Normally you would extend the IdentityDbContext class and put your application specific tables into this context. This would look something similar to the following
public class BlogContext : IdentityDbContext<ApplicationUser>
{
public BlogContext()
: base("BlogConnection")
{
}
public DbSet<Post> Posts { get; set; }
public DbSet<Comment> Comments { get; set; }
}
There are edge-cases where it is better to separate your application data from the one's hold by Identity. One case could be when your application data is not related to your user data and you want to keep them separate. Nevertheless, when creating a separate context for your application data you should keep in mind that you have to deal with two contexts, which can be painful sometimes.
Upvotes: 1