| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.Linq;
|
|---|
| 4 | using System.Linq.Expressions;
|
|---|
| 5 | using System.Text;
|
|---|
| 6 |
|
|---|
| 7 | namespace Wierszowki.Core.Interfaces
|
|---|
| 8 | {
|
|---|
| 9 | /// <summary>
|
|---|
| 10 | /// Contact for the Repository pattern
|
|---|
| 11 | /// </summary>
|
|---|
| 12 | /// <typeparam name="T"></typeparam>
|
|---|
| 13 | public interface IRepository<T>
|
|---|
| 14 | where T : IIdentifiable
|
|---|
| 15 | {
|
|---|
| 16 | /// <summary>
|
|---|
| 17 | /// Returns a count of the items in the repository
|
|---|
| 18 | /// </summary>
|
|---|
| 19 | int Count();
|
|---|
| 20 |
|
|---|
| 21 | /// <summary>
|
|---|
| 22 | /// Returns a count of the items in the repository which match the supplied lambda
|
|---|
| 23 | /// </summary>
|
|---|
| 24 | /// <param name="expression">A lambda expression which will be evaluated against the repository</param>
|
|---|
| 25 | int Count(Expression<Func<T, bool>> expression);
|
|---|
| 26 |
|
|---|
| 27 | /// <summary>
|
|---|
| 28 | /// Adds a new entity in to the repository
|
|---|
| 29 | /// </summary>
|
|---|
| 30 | void Insert(T entity);
|
|---|
| 31 |
|
|---|
| 32 | /// <summary>
|
|---|
| 33 | /// Removes the specified entity from the repository
|
|---|
| 34 | /// </summary>
|
|---|
| 35 | void Delete(T entity);
|
|---|
| 36 |
|
|---|
| 37 | /// <summary>
|
|---|
| 38 | /// Saves the specified entity back to the repository
|
|---|
| 39 | /// </summary>
|
|---|
| 40 | void Update(T entity);
|
|---|
| 41 |
|
|---|
| 42 | /// <summary>
|
|---|
| 43 | /// Finds a single instance of an entity matching a unique identifier.
|
|---|
| 44 | /// </summary>
|
|---|
| 45 | T FindOne(int id);
|
|---|
| 46 |
|
|---|
| 47 | /// <summary>
|
|---|
| 48 | /// Finds a single instance of an entity matching a lambda expression
|
|---|
| 49 | /// </summary>
|
|---|
| 50 | /// <returns>The first entity which matches the expession</returns>
|
|---|
| 51 | T FindOne(Expression<Func<T, bool>> expression);
|
|---|
| 52 |
|
|---|
| 53 | /// <summary>
|
|---|
| 54 | /// Tries the find one.
|
|---|
| 55 | /// </summary>
|
|---|
| 56 | /// <param name="expression">The expression.</param>
|
|---|
| 57 | /// <param name="entity">The entity.</param>
|
|---|
| 58 | /// <returns></returns>
|
|---|
| 59 | bool TryFindOne(Expression<Func<T, bool>> expression, out T entity);
|
|---|
| 60 |
|
|---|
| 61 | /// <summary>
|
|---|
| 62 | /// Tries the find one.
|
|---|
| 63 | /// </summary>
|
|---|
| 64 | /// <param name="expression">The expression.</param>
|
|---|
| 65 | /// <returns></returns>
|
|---|
| 66 | bool Exists(Expression<Func<T, bool>> expression);
|
|---|
| 67 |
|
|---|
| 68 | /// <summary>
|
|---|
| 69 | /// Finds all entities in the repository
|
|---|
| 70 | /// </summary>
|
|---|
| 71 | /// <returns></returns>
|
|---|
| 72 | IList<T> FindAll();
|
|---|
| 73 |
|
|---|
| 74 | /// <summary>
|
|---|
| 75 | /// Finds all entities matching a lambda expression
|
|---|
| 76 | /// </summary>
|
|---|
| 77 | /// <param name="expression">The expression.</param>
|
|---|
| 78 | /// <returns></returns>
|
|---|
| 79 | IList<T> FindAll(Expression<Func<T, bool>> expression);
|
|---|
| 80 |
|
|---|
| 81 | /// <summary>
|
|---|
| 82 | /// Returns a requeryable set of all entities in the repository
|
|---|
| 83 | /// </summary>
|
|---|
| 84 | IQueryable<T> Find();
|
|---|
| 85 |
|
|---|
| 86 | /// <summary>
|
|---|
| 87 | /// Returns a requeryable set of all entities in the repository matching a unique identifier
|
|---|
| 88 | /// </summary>
|
|---|
| 89 | IQueryable<T> Find(int id);
|
|---|
| 90 |
|
|---|
| 91 | /// <summary>
|
|---|
| 92 | /// Returns a requeryable set of all entities in the repository matching a lambda expression
|
|---|
| 93 | /// </summary>
|
|---|
| 94 | IQueryable<T> Find(Expression<Func<T, bool>> expression);
|
|---|
| 95 | }
|
|---|
| 96 | } |
|---|