Skip to content

Instantly share code, notes, and snippets.

@lucasselliach
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasselliach/b83ee0d3615b5fa567e7 to your computer and use it in GitHub Desktop.
Save lucasselliach/b83ee0d3615b5fa567e7 to your computer and use it in GitHub Desktop.
All RepositoryBase
public interface IRepositoryBase<TEntity> where TEntity : class
{
void Add(TEntity obj);
TEntity GetById(int id);
IEnumerable<TEntity> GetAll();
void Update(TEntity obj);
void Remove(TEntity obj);
void Dispose();
}
public class RepositoryBase<TEntity> : IDisposable, IRepositoryBase<TEntity> where TEntity : class
{
protected MyMoneyContext MyMoneyDataBase = new MyMoneyContext();
public void Add(TEntity obj)
{
MyMoneyDataBase.Set<TEntity>().Add(obj);
MyMoneyDataBase.SaveChanges();
}
public TEntity GetById(int id)
{
return MyMoneyDataBase.Set<TEntity>().Find(id);
}
public IEnumerable<TEntity> GetAll()
{
return MyMoneyDataBase.Set<TEntity>().ToList();
}
public void Update(TEntity obj)
{
MyMoneyDataBase.Entry(obj).State = EntityState.Modified;
MyMoneyDataBase.SaveChanges();
}
public void Remove(TEntity obj)
{
MyMoneyDataBase.Set<TEntity>().Remove(obj);
MyMoneyDataBase.SaveChanges();
}
void IRepositoryBase<TEntity>.Dispose()
{
throw new NotImplementedException();
}
void IDisposable.Dispose()
{
throw new NotImplementedException();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment