Models.ApplicationDbContext在一个Asp.Net MVC 5应用程序的所有型号? [英] Models.ApplicationDbContext for all models in an Asp.Net MVC 5 application?
问题描述
我创建一个Asp.Net MVC 5网站。的我需要为添加自定义在ApplicationUser领域和联系人(添加外键)与其他车型。的我想我应该只使用一个上下文类型。然而,code脚手架已经生成以下 ApplicationDbContext
类。可我只是把我的公共DbSet< ...> ... {搞定;组; }
中的类?还是有更好的模式?
命名空间MyApp.Models
{
//可以通过增加更多的属性User类为用户添加配置文件数据,请访问http://go.microsoft.com/fwlink/?LinkID=317594,以了解更多信息。
公共类ApplicationUser:用户
{
} 公共类ApplicationDbContext:IdentityDbContextWithCustomUser< ApplicationUser>
{
}
}
有一个出色的视频解释此事。
只要检查由斯科特·艾伦的免费ASP.NET MVC 5基础课程。
确切的<一个href=\"http://pluralsight.com/training/Player?author=scott-allen&name=aspdotnet-mvc5-fundamentals-m6-ef6&mode=live&clip=2&course=aspdotnet-mvc5-fundamentals\">answer在这里(开始于3:30)。
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>
{
}
}
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).
这篇关于Models.ApplicationDbContext在一个Asp.Net MVC 5应用程序的所有型号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!