开发者

How to design an application using Entity Framework 4.1, POCOs, and the Repository Pattern

开发者 https://www.devze.com 2023-03-07 02:23 出处:网络
I\'m trying to design an application, in ASP.NET MVC, using Enterprise Library 4.1I added the Entity Framework POCO template and moved the generated entities to a separate \"Entities\" project.However

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 p开发者_运维问答roject, 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消