Created
October 1, 2018 23:03
-
-
Save obrassard/b782cd2c707e8bbd79b4151be9968b08 to your computer and use it in GitHub Desktop.
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 Repository<T> where T : class | |
{ | |
private DbSet<T> m_dbset; | |
private BaremoContext m_context; | |
public Repository(DbSet<T> dbset, BaremoContext context) | |
{ | |
m_dbset = dbset; | |
m_context = context; | |
} | |
public IEnumerable<T> GetAll() | |
{ | |
return m_dbset; | |
} | |
public T GetSingleById(int Id) | |
{ | |
return m_dbset.Find(Id); | |
} | |
public void Insert(T obj) | |
{ | |
m_dbset.Add(obj); | |
} | |
public void Update(T obj) | |
{ | |
m_context.Entry(obj).State = EntityState.Modified; | |
} | |
public void Delete(int Id) | |
{ | |
T getObjById = m_dbset.Find(Id); | |
m_dbset.Remove(getObjById); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment