Last active
August 29, 2015 14:18
-
-
Save lucasselliach/b83ee0d3615b5fa567e7 to your computer and use it in GitHub Desktop.
All RepositoryBase
This file contains 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
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(); | |
} |
This file contains 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
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