Skip to content

Instantly share code, notes, and snippets.

@codebeaulieu
Created July 15, 2015 00:31
Show Gist options
  • Save codebeaulieu/610c09e67b5c1c4343f4 to your computer and use it in GitHub Desktop.
Save codebeaulieu/610c09e67b5c1c4343f4 to your computer and use it in GitHub Desktop.
my repository
public class BlogEngineRepository<T> : IRepository<T> where T : class
{
protected DbSet<T> DbSet;
public BlogEngineRepository(DbContext dataContext)
{
DbSet = dataContext.Set<T>();
}
#region IRepository<T> Members
public void Insert(T entity)
{
DbSet.Add(entity);
}
public void Delete(T entity)
{
DbSet.Remove(entity);
}
public IQueryable<T> SearchFor(Expression<Func<T, bool>> predicate)
{
return DbSet.Where(predicate);
}
public IQueryable<T> GetAll()
{
return DbSet;
}
public T GetById(int id)
{
return DbSet.Find(id);
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment