Click here to Skip to main content
15,791,526 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm implementing EF6 using Generic Repository Pattern. how I can implement Transaction?

my project structure is as below

DataAccess Layer in which I have Generic Repository Pattern class

public interface IGenericRepository<t> where T : class {

    IQueryable<t> GetAll();
    IQueryable<t> FindBy(Expression<func>&lt;t,>> predicate);
    void Add(T entity);
    void Delete(T entity);
    void Edit(T entity);
    void Save();

In Domain Layer I need to perform multiple insertions through Generic Repository. how i can implement transaction.Without adding the EntityFramework reference in Domain layer, how i can achieve this
Updated 12-Aug-15 11:12am

1 solution

As far as I know a single save will be wrapped inside a transaction by EF even if it contains several operations. However, if you need to go beyond that, one way is to use TransactionScope[^] to define the boundaries of the transaction.

There's a good discussion about transactions and EF at Working with Transactions (EF6 Onwards)[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900