Last active
September 12, 2019 10:24
-
-
Save dileno/5b74095e49b6ee3c3cf91921d0916e85 to your computer and use it in GitHub Desktop.
DataRepository
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 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