如何使用 Entity Framework 4.1、POCO 和存储库模式设计应用程序
我正在尝试使用 Enterprise Library 4.1 在 ASP.NET MVC 中设计一个应用程序,我添加了实体框架 POCO 模板并将生成的实体移动到单独的“实体”项目中。但是,我很难确定设计此应用程序的最佳方法。我假设 ObjectContext 应该与 EDMX 文件位于同一项目中。但 ObjectContext 必须有权访问 POCO。如果我创建存储库,它们将需要访问 POCO 和 ObjectContext。我假设存储库逻辑和 POCO 应该位于同一个项目中,但这行不通,因为“POCO 项目”和“EDMX 项目”之间会存在循环引用。我不想将 ObjectContext 放入“POCOs 项目”中,因为该项目不应引用 System.Data。
我四处寻找示例,但我发现的几乎所有示例都将示例放在一起,而没有使用最佳实践。也许我把这件事想得太复杂了。我只是想了解如何最好地设计应用程序。
I'm trying to design an application, in ASP.NET MVC, using Enterprise Library 4.1 I added the Entity Framework POCO template and moved the generated entities to a separate "Entities" project. However, I'm having a hard time determining the best way to design this application. I'm assuming the ObjectContext should be in the same project as the EDMX file. But the ObjectContext has to have access to the POCOs. If I create repositories they would need to have access to both the POCOs and the ObjectContext. I'm assuming that the repository logic and the POCOs should be in the same project, but that wouldn't work because there would be a circular reference between the "POCOs project" and the "EDMX project." I don't want to put the ObjectContext in the "POCOs project" because that project shouldn't reference System.Data.
I've searched around for examples, but almost ever example I find throws the example together without the use of best practices. Maybe I'm making this too complicated. I'm just trying to understand how to best design applications.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想使用 POCO,您应该首先查看 Entity Framework Code First 并完全跳过 EDMX 文件。 Project Silk 就是 Microsoft 推出的一个很好的例子。我会做一些稍微不同的事情,但总的来说它涵盖了 EF4.1、POCOS 和您提到的存储库模式。 Shrinkr 是另一个很好的示例项目。一个稍小但仍然很好的示例是 EFMVC,它主要关注 EF 的存储库模式。
If you are looking to use POCO's, you should look at Entity Framework Code First and skip the EDMX file altogether. Project Silk is a good example of this put out by Microsoft. I would do something slightly different but overall it covers EF4.1, POCOS, and repository pattern like you mentioned. Shrinkr is another good example project. A slightly smaller but still good example is EFMVC which mainly just focuses on the repository pattern with EF.