简体   繁体   English

ASP MVC3区域dbcontext

[英]ASP MVC3 areas dbcontext

I'm a newbie to C# ASP development but I'm using it to develop a web application using MVC3. 我是C#ASP开发的新手,但是我正在使用它来开发使用MVC3的Web应用程序。

I have created an application which has common components and have broken down the services that the site provides into 'areas'. 我创建了一个具有通用组件的应用程序,并将该站点提供的服务分解为“区域”。 I would like to keep each area seperate as far as possible and so have created a DbContext for the application and one for each area. 我想使每个区域尽可能分开,因此为应用程序创建了一个DbContext,为每个区域创建了一个DbContext。

I'd like to use a database initializer to initialise each of the areas but I'm not sure how to approach this. 我想使用数据库初始化程序来初始化每个区域,但是我不确定该如何处理。

Is this the best architectural approach to take? 这是最好的建筑方法吗? If so, how do I create multiple area intializers for this configuration. 如果是这样,如何为该配置创建多个区域初始化器。 If not, how would you approach this problem in C# MVC3? 如果没有,您将如何在C#MVC3中解决此问题?

Thanks in advance, 提前致谢,

Niall 尼尔

You can only set one DbContext for a application. 您只能为一个应用程序设置一个DbContext。 You would only use diffent DbContext objects if you where to use multiple databases. 如果要在多个数据库中使用,则仅使用不同的DbContext对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM