Skip to content

Instantly share code, notes, and snippets.

@obrassard
Created October 1, 2018 23:03
Show Gist options
  • Save obrassard/b782cd2c707e8bbd79b4151be9968b08 to your computer and use it in GitHub Desktop.
Save obrassard/b782cd2c707e8bbd79b4151be9968b08 to your computer and use it in GitHub Desktop.
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