Skip to content

Instantly share code, notes, and snippets.

@oclockvn
Created March 5, 2017 15:23
Show Gist options
  • Save oclockvn/e32745c249807984332e42d227c6c037 to your computer and use it in GitHub Desktop.
Save oclockvn/e32745c249807984332e42d227c6c037 to your computer and use it in GitHub Desktop.
implement repository pattern in asp.net mvc
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