asp.net mvc 3个领域中的模型
如何组织多个区域的模型?我正在尝试使用区域来组织代码。我使用的是 Visual Studio 2010 Express ,该项目位于 asp.net mvc3 上,并且使用代码优先开发。互联网上的所有教程和参考资料都只讨论控制器和路线,但是模型呢?更准确地说,我正在寻找以下建议:
- 区域中的模型文件夹将包含其自己的类,因此在哪里 应该放置 dbcontext 吗?我已经有一个 dbcontext 类 “根”模型文件夹中包含多个 dbset 条目。我可以吗 有多个 dbcontext 将其数据存储在同一个数据库中吗?
- 我已经完成了 ASP.NET MVC 可移植区域项目 mvccontrib,但它仍然在 asp.net mvc2 中,但这是唯一的方法 在 asp.net mvc 3 中构建插件/组件?
- 除了区域/可移动区域之外,还有什么更好的组织方式 代码是一种可以简单地“插入”新功能的方式, 无需对现有代码进行太多更改?区域外观 有前途,但我无法弄清楚模型应该如何 放置。
- 区域仅适用于控制器和视图分离吗?
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 :
- 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 ? - 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 ? - 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. - Are areas only good for controller and view separation ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我一直在研究实现 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 ...
区域的注册代码很好地提示了区域的用途 - 分隔路线和对特定控制器的访问。 (想想逻辑用户界面单元)。为了组织代码,命名空间是首选工具。
也许看看 Umbraco、Orchard 甚至 N2CMS 之类的东西,看看他们如何管理扩展。
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.