Created
March 5, 2017 15:23
-
-
Save oclockvn/e32745c249807984332e42d227c6c037 to your computer and use it in GitHub Desktop.
implement repository pattern in asp.net mvc
This file contains hidden or 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
namespace didongexpress.repos | |
{ | |
public interface IRepository : IDisposable | |
{ | |
} | |
public interface IRepository<T> : IRepository where T : class | |
{ | |
IQueryable<T> Query(Expression<Func<T, bool>> predicate); | |
List<T> All(Expression<Func<T, bool>> predicate); | |
T GetById(object id); | |
T Create(T model); | |
T Update(T model, List<Expression<Func<T, object>>> updateProperties = null); | |
T Delete(T model); | |
T Delete(object id); | |
} | |
public class GenericRepository<T> : IRepository<T> where T : class | |
{ | |
protected bool disposed = false; | |
protected ExpressDb db = null; | |
protected DbSet table; | |
public GenericRepository(ExpressDb db) | |
{ | |
this.db = db; | |
} | |
public IQueryable<T> Query(Expression<Func<T, bool>> predicate) | |
{ | |
throw new NotImplementedException(); | |
} | |
public virtual List<T> All(Expression<Func<T, bool>> predicate) | |
{ | |
throw new NotImplementedException(); | |
} | |
public virtual T Create(T model) | |
{ | |
throw new NotImplementedException(); | |
} | |
public virtual T Delete(object id) | |
{ | |
throw new NotImplementedException(); | |
} | |
public virtual T Delete(T model) | |
{ | |
throw new NotImplementedException(); | |
} | |
public virtual T GetById(object id) | |
{ | |
throw new NotImplementedException(); | |
} | |
public virtual T Update(T model, List<Expression<Func<T, object>>> updateProperties = null) | |
{ | |
throw new NotImplementedException(); | |
} | |
public void Dispose() | |
{ | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
protected void Dispose(bool disposing) | |
{ | |
if (!disposed) | |
{ | |
if (disposing) | |
{ | |
if (db != null) | |
{ | |
db.Dispose(); | |
db = null; | |
} | |
} | |
disposed = true; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment