Created
October 11, 2017 15:20
-
-
Save cosoria/38766e1d4b4289aaff6441983db4055e to your computer and use it in GitHub Desktop.
EntityFramework Unit of Work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EntityFrameworkUnitOfWork : IEntityFrameworkUnitOfWork | |
{ | |
private readonly IEntityFrameworkContext _context; | |
public EntityFrameworkUnitOfWork(IEntityFrameworkContext context) | |
{ | |
_context = context; | |
} | |
public IEntityFrameworkContext Context | |
{ | |
get { return _context; } | |
} | |
public void Save() | |
{ | |
_context.SaveChanges(); | |
} | |
public void Dispose() | |
{ | |
if (_context != null) | |
{ | |
_context.Dispose(); | |
} | |
} | |
} | |
public class EntityFrameworkUnitOfWork<TContext> : EntityFrameworkUnitOfWork, IEntityFrameworkUnitOfWork<TContext> where TContext : class, IEntityFrameworkContext | |
{ | |
private readonly TContext _context; | |
public new TContext Context | |
{ | |
get { return _context; } | |
} | |
public EntityFrameworkUnitOfWork(TContext context) : base(context) | |
{ | |
_context = context; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment