Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 the 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?

like image 389
marvelTracker Avatar asked Jul 27 '11 10:07

marvelTracker


People also ask

Do we need unit of work with Entity Framework?

Not necessarily. EF already provides the unit of work pattern for you. The only reason to still have a unit of work is if you: want to include non-EF-datasources in an atomic data operation.

Why do we need unit of work pattern?

The unit of work class serves one purpose: to make sure that when you use multiple repositories, they share a single database context. That way, when a unit of work is complete you can call the SaveChanges method on that instance of the context and be assured that all related changes will be coordinated.

What is unit of work pattern in Entity Framework?

Unit of Work is the concept related to the effective implementation of the repository pattern. non-generic repository pattern, generic repository pattern. Unit of Work is referred to as a single transaction that involves multiple operations of insert/update/delete and so on.

Do we need repository pattern with Entity Framework Core?

Developers building applications with ASP.Net Core and Entity Framework Core should not use UoW and Repository pattern anymore. EF Core supports unit testing and mock contexts.


1 Answers

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

like image 164
tdykstra Avatar answered Oct 13 '22 10:10

tdykstra