asp.net mvc 3个领域中的模型

发布于 2025-01-01 00:27:42 字数 564 浏览 0 评论 0原文

如何组织多个区域的模型?我正在尝试使用区域来组织代码。我使用的是 Visual Studio 2010 Express ,该项目位于 asp.net mvc3 上,并且使用代码优先开发。互联网上的所有教程和参考资料都只讨论控制器和路线,但是模型呢?更准确地说,我正在寻找以下建议:

  1. 区域中的模型文件夹将包含其自己的类,因此在哪里 应该放置 dbcontext 吗?我已经有一个 dbcontext 类 “根”模型文件夹中包含多个 dbset 条目。我可以吗 有多个 dbcontext 将其数据存储在同一个数据库中吗?
  2. 我已经完成了 ASP.NET MVC 可移植区域项目 mvccontrib,但它仍然在 asp.net mvc2 中,但这是唯一的方法 在 asp.net mvc 3 中构建插件/组件?
  3. 除了区域/可移动区域之外,还有什么更好的组织方式 代码是一种可以简单地“插入”新功能的方式, 无需对现有代码进行太多更改?区域外观 有前途,但我无法弄清楚模型应该如何 放置。
  4. 区域仅适用于控制器和视图分离吗?

How to organize models in multiple areas ? I am trying to organize code using areas. I am using visual studio 2010 express , the project is on asp.net mvc3 and code-first development is used. All the tutorial and reference over internet only talks about controllers and routes, but what about models ? more precisely, I am looking for suggestions around :

  1. The model folder in an area will contain its own classes, so where
    should the dbcontext be placed ? I already have an dbcontext class
    containing multiple dbset entries in the "root" model folder. Can i
    have multiple dbcontext storing its data in the same database ?
  2. I have gone through asp.net mvc portable areas project by
    mvccontrib, but its still in asp.net mvc2, but is that the only way
    around for building plugins/components in asp.net mvc 3 ?
  3. Apart from areas/portable areas, is there any better way to organize
    code is such a way that new features can be simply "dropped-in",
    without doing too much changes in existing code ? Areas looks
    promising but i am not able to figure out how models should be
    placed.
  4. Are areas only good for controller and view separation ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寒冷纷飞旳雪 2025-01-08 00:27:42
  1. dbcontext 将位于数据访问层或数据访问文件夹中,您将在其中管理所有数据访问文件。你会
    无论您想在模型中使用这些类,都可以引用它们。
    是的!您可以让多个 dbcontext 将其数据存储在同一个数据库中。

  2. 不知道。

  3. 我或我的团队最好的方法是保持视图/模型/控制器完全独立。这样一来,如果一个人
    专门讨论观点或如何展示它们,其他可以写
    控制器对其执行的操作。

  4. 我们不使用区域,因为当您的应用程序倾向于以指数方式扩展时,您可能会失去对什么在哪里的把握?我的
    口头禅:4个文件夹:View/Model/ViewModel/Controller。

其他人可能有不同的看法...

  1. The dbcontext will be in data access layer or your data access folder where you will manage all your data access files. You will
    reference these classes in your models wherever you want to use them.
    Yes! You can have multiple dbcontext storing its data in the same db.

  2. No Idea.

  3. The best way I or my team does is to maintain views/models/controllers totally separate. In that way if one person
    is dedicated to the views or how to show them, other can write
    controller actions for it.

  4. We dont use areas as because when your application tend to scale in a exponential manner, you might will loose hold of what is where? My
    mantra: 4 folders: View/Model/ViewModel/Controller.

Any other person might have different view...

双马尾 2025-01-08 00:27:42

我一直在研究实现 DbContext 的模型级别分离的可能方法,到目前为止我发现没有直接的方法让多个 dbcontext 使用 Code-First 将数据存储在同一个数据库中。这只有通过模型优先设计才有可能实现。使用代码优先的多个 dbinitializer 不起作用,因为所有尝试都尝试初始化数据库,并且只有第一个会成功。
但是,可能有某种方法可以通过使用 DbModelBuilder 动态创建数据库来解决,就像 Orchard CMS 和其他一些开源项目中所做的那样。有人试过吗?请分享...

I've been looking into possible ways to achieve the model level separation of DbContext, so far what i found is that there is no direct way to have multiple dbcontext storing data in the same database with Code-First. It is only possible with Model-First design. With code-first multiple dbinitializers doesn't works as all try to initialize the database and only the first one will succeed.
However, there might be some way around by dynamically creating the database using DbModelBuilder as done in orchard CMS and some other Open source projects. Anybody tried it ? Please share ...

眼趣 2025-01-08 00:27:42
  1. 区域仅适用于视图模型分离。

区域的注册代码很好地提示了区域的用途 - 分隔路线和对特定控制器的访问。 (想想逻辑用户界面单元)。为了组织代码,命名空间是首选工具。

也许看看 Umbraco、Orchard 甚至 N2CMS 之类的东西,看看他们如何管理扩展。

  1. Areas are only good for view model separation.

The registration code of an area is a good hint towards what areas are used for - separating out routes and access to specific controllers. (Think logical user interface units). For organising your code, namespaces are the tool of choice.

Perhaps look at something like Umbraco, Orchard or even N2CMS to see how they manage extensions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文