Models.ApplicationDbContext for all models in an Asp.Net MVC 5 application?

asp.net asp.net-mvc asp.net-mvc-5 c# entity-framework

Question

I've creating an Asp.Net MVC 5 website. I will need to add customized fields in ApplicationUser and associate (add foreign keys) it with other models. I think I should just use one context type. However, the code scaffold already generate the following ApplicationDbContext class. Can I just put all my public DbSet<...> ... { get; set; } in the class? Or is there a better pattern?

namespace MyApp.Models
{
    // You can add profile data for the user by adding more properties to your User class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
    public class ApplicationUser : User
    {  
    }

    public class ApplicationDbContext : IdentityDbContextWithCustomUser<ApplicationUser>
    {
    }
}
1
30
6/6/2015 3:16:39 PM

Popular Answer

There is an excellent video explaining that matter. Just check the free ASP.NET MVC 5 Fundamentals course by Scott Allen. The exact answer is here (starts at 3:30).

28
5/31/2014 1:15:42 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow