Dnyaneshwar
Dnyaneshwar

Reputation: 49

What is the difference between TransactionScope and Unit of work in Entity Framework

Recently I learned Unit of work in entity framework.Now one question cames in mind is that what is the difference between TransactionScope and unitOfWork layer.I think both are doing same thing.Is it correct?

Upvotes: 4

Views: 3089

Answers (2)

Worthy7
Worthy7

Reputation: 1561

Transactions are an implementation of the design pattern Unit of Work.

What we are talking about here is just the level of abstraction.

  1. At the top we have Unit of work which is applicable to anything.
  2. Next, we might have a dot net level abstraction, which would be Transactions.
  3. Next we have Entity Framework which is a dot net repository level abstraction which implements Transactions.
  4. Finally we have your database SQL Server which is wrapped and used by Entity Framework

So basically, it is the context. If we are talking in terms of a RDMS we would say Transaction. In a dot net context, you can say Transaction Scope and in a software design context, it is a Unit of Work.

Upvotes: 0

Ola Ekdahl
Ola Ekdahl

Reputation: 1514

They are two completely different things. Unit of work is a design pattern or a set of guidelines for how to solve a software problem. TransactionScope is a class that I can use to programmatically define just that, a scope for a transaction.

More info here:

Unit of work - http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application

TransactionScope - https://msdn.microsoft.com/library/bb738523(v=vs.100).aspx

Upvotes: 3

Related Questions