Skip to content

Instantly share code, notes, and snippets.

@cosoria
Created October 11, 2017 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cosoria/38766e1d4b4289aaff6441983db4055e to your computer and use it in GitHub Desktop.
Save cosoria/38766e1d4b4289aaff6441983db4055e to your computer and use it in GitHub Desktop.
EntityFramework Unit of Work
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