开发者

Is Unit of Work pattern required in Entity Framework 4.0

How we can use Unit of Work pattern with (Entity Framework 4.1) code first approach? As I know, EF 4.1 has internally implemented t开发者_高级运维he Unit of Work and repository patterns. If we use self tracking and Data Transfer Objects pattern do we also need to implement a Unit Of Work pattern?


In response to your first question, you can find an example of the unit of work pattern implemented with EF Code First here: http://www.asp.net/entity-framework/tutorials/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application


If you use web services and stateless things, you need to track user entity state manually because DBContext should be disposable (the recommended usage). In other words, DBContext should be wrapped within a Using Block. The Unit of work pattern helps to reduce the dependency between Entity Framework and your infrastructure layer. This is ideal for stateless implementations like WCF services over DTO.


Check this out, too. This is a decent example of the UoW and Repository patterns in an application.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜