Matthew Joseph (Matthew0234)

Matthew0234

Geek Repo

Company:WfMatthew

Github PK Tool:Github PK Tool

Matthew Joseph's repositories

Public-Class-Repository-

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 public class Repository<T> : IRepository<T> where T : EntityBase { private readonly ApplicationDbContext _dbContext; public Repository(ApplicationDbContext dbContext) { _dbContext = dbContext; } public virtual T GetById(int id) { return _dbContext.Set<T>().Find(id); } public virtual IEnumerable<T> List() { return _dbContext.Set<T>().AsEnumerable(); } public virtual IEnumerable<T> List(System.Linq.Expressions.Expression<Func<T, bool>> predicate) { return _dbContext.Set<T>() .Where(predicate) .AsEnumerable(); } public void Insert(T entity) { _dbContext.Set<T>().Add(entity); _dbContext.SaveChanges(); } public void Update(T entity) { _dbContext.Entry(entity).State = EntityState.Modified; _dbContext.SaveChanges(); } public void Delete(T entity) { _dbContext.Set<T>().Remove(entity); _dbContext.SaveChanges(); }

Stargazers:3Issues:0Issues:0

Have-a-nice-day

Good luck with your job

Stargazers:2Issues:0Issues:0