Skip to content

Instantly share code, notes, and snippets.

@dileno
Last active September 12, 2019 10:24
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 dileno/5b74095e49b6ee3c3cf91921d0916e85 to your computer and use it in GitHub Desktop.
Save dileno/5b74095e49b6ee3c3cf91921d0916e85 to your computer and use it in GitHub Desktop.
DataRepository
public class DataRepository<T> : IDataRepository<T> where T : class
{
private readonly BlogPostsContext _context;
public DataRepository(BlogPostsContext context)
{
_context = context;
}
public void Add(T entity)
{
_context.Set<T>().Add(entity);
}
public void Update(T entity)
{
_context.Set<T>().Update(entity);
}
public void Delete(T entity)
{
_context.Set<T>().Remove(entity);
}
public async Task<T> SaveAsync(T entity)
{
await _context.SaveChangesAsync();
return entity;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment