Created
July 3, 2013 22:32
-
-
Save shawnmclean/5923429 to your computer and use it in GitHub Desktop.
Generic Repository Interface
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 IRepository<T> where T : class | |
{ | |
/// <summary> | |
/// Gets all objects from database | |
/// </summary> | |
IQueryable<T> All(params string[] includes); | |
/// <summary> | |
/// Gets objects from database by filter. | |
/// </summary> | |
/// <param name="predicate">Specified a filter</param> | |
IQueryable<T> Filter(Expression<Func<T, bool>> predicate, params string[] includes); | |
/// <summary> | |
/// Gets objects from database with filting and paging. | |
/// </summary> | |
/// <typeparam name="Key"></typeparam> | |
/// <param name="filter">Specified a filter</param> | |
/// <param name="total">Returns the total records count of the filter.</param> | |
/// <param name="index">Specified the page index.</param> | |
/// <param name="size">Specified the page size</param> | |
IQueryable<T> Filter<Key>(Expression<Func<T, bool>> filter, out int total, int index = 0, int size = 50, params string[] includes); | |
/// <summary> | |
/// Gets the object(s) is exists in database by specified filter. | |
/// </summary> | |
/// <param name="predicate">Specified the filter expression</param> | |
bool Contains(Expression<Func<T, bool>> predicate); | |
/// <summary> | |
/// Find object by keys. | |
/// </summary> | |
/// <param name="keys">Specified the search keys.</param> | |
T Find(params object[] keys); | |
/// <summary> | |
/// Find object by specified expression. | |
/// </summary> | |
/// <param name="predicate"></param> | |
/// <param name="eagerLoadEntities"></param> | |
T Find(Expression<Func<T, bool>> predicate, params string[] includes); | |
/// <summary> | |
/// Create a new object to database. | |
/// </summary> | |
/// <param name="t">Specified a new object to create.</param> | |
void Create(T t); | |
/// <summary> | |
/// Delete the object from database. | |
/// </summary> | |
/// <param name="t">Specified a existing object to delete.</param> | |
void Delete(T t); | |
/// <summary> | |
/// Delete objects from database by specified filter expression. | |
/// </summary> | |
/// <param name="predicate"></param> | |
void Delete(Expression<Func<T, bool>> predicate); | |
/// <summary> | |
/// Update object changes and save to database. | |
/// </summary> | |
/// <param name="t">Specified the object to save.</param> | |
void Update(T t); | |
/// <summary> | |
/// Get the total objects count. | |
/// </summary> | |
int Count(); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="predicate"></param> | |
/// <returns></returns> | |
int Count(Expression<Func<T, bool>> predicate); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment