Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IRepository<T>
- {
- void Add(T item);
- T Find(object id);
- IEnumerable<T> List();
- }
- public class PostgresqlRepository<T,K> : IRepository<T> where T : class
- where K : DbContext,new()
- {
- public void Add(T item)
- {
- using (var db = new K())
- {
- db.Set<T>().Add(item);
- db.SaveChanges();
- }
- }
- public T Find(object id)
- {
- using (var db = new K())
- {
- return db.Set<T>().Find(id);
- }
- }
- public IEnumerable<T> List()
- {
- using (var db = new K())
- {
- return db.Set<T>().ToList();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement