Created
August 24, 2012 04:09
-
-
Save shawnmclean/3445335 to your computer and use it in GitHub Desktop.
Example of a 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(); | |
/// <summary> | |
/// Gets objects from database by filter. | |
/// </summary> | |
/// <param name="predicate">Specified a filter</param> | |
IQueryable<T> Filter(Expression<Func<T, bool>> predicate); | |
/// <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); | |
/// <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> | |
T Find(Expression<Func<T, bool>> predicate); | |
/// <summary> | |
/// Find object by specified expression and eager loading related fields | |
/// </summary> | |
/// <param name="predicate"></param> | |
/// <param name="children"></param> | |
/// <returns></returns> | |
T Find(Expression<Func<T, bool>> predicate, List<string> children); | |
/// <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 { get; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where is the implementation for function Filter