forked from SharpRepository/SharpRepository
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathICrudRepository.cs
More file actions
129 lines (105 loc) · 5.4 KB
/
Copy pathICrudRepository.cs
File metadata and controls
129 lines (105 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using SharpRepository.Repository.Caching;
namespace SharpRepository.Repository
{
public interface ICrudRepository<T, TKey> : IRepositoryBase<T> where T : class
{
IRepositoryConventions Conventions { get; set; }
/// <summary>
/// Returns the Type for the entity of this repository.
/// </summary>
Type EntityType { get; }
/// <summary>
/// Returns the Type for the key of this repository.
/// </summary>
Type KeyType { get; }
/// <summary>
/// Gets the specified entity of type <typeparamref name="T"/> from the repository by the primary key.
/// </summary>
/// <param name="key">The primary key.</param>
/// <returns>The entity that matches on the primary key</returns>
T Get(TKey key);
/// <summary>
/// Gets the specified entity of type <typeparamref name="T"/> from the repository by the primary key and maps it to the result of type <typeparamref name="TResult"/>.
/// </summary>
/// <typeparam name="TResult">The type of the result.</typeparam>
/// <param name="key">The primary key.</param>
/// <param name="selector">The mapping selector that returns the result type.</param>
/// <returns>The mapped entity based on the selector that matches on the primary key.</returns>
TResult Get<TResult>(TKey key, Expression<Func<T, TResult>> selector);
/// <summary>
/// Gets the specified entity of type <typeparamref name="T"/> from the repository by the primary key.
/// </summary>
/// <param name="keys">The primary keys.</param>
/// <returns>The entity that matches on the primary key</returns>
IEnumerable<T> GetMany(params TKey[] keys);
/// <summary>
/// Gets the specified entity of type <typeparamref name="T"/> from the repository by the primary key.
/// </summary>
/// <param name="keys">The primary keys.</param>
/// <returns>The entity that matches on the primary key</returns>
IEnumerable<T> GetMany(IEnumerable<TKey> keys);
IEnumerable<TResult> GetMany<TResult>(Expression<Func<T, TResult>> selector, params TKey[] keys);
IEnumerable<TResult> GetMany<TResult>(IEnumerable<TKey> keys, Expression<Func<T, TResult>> selector);
IDictionary<TKey, T> GetManyAsDictionary(params TKey[] keys);
IDictionary<TKey, T> GetManyAsDictionary(IEnumerable<TKey> keys);
/// <summary>
/// Returns true if the specified entity of type <typeparamref name="T"/> from the repository by the primary key exists
/// </summary>
/// <param name="key">The primary key.</param>
/// <returns>True if the entity exists, false if it does not</returns>
bool Exists(TKey key);
/// <summary>
/// Returns true if the specified entity of type <typeparamref name="T"/> from the repository by the primary key exists
/// </summary>
/// <param name="key">The primary key.</param>
/// <param name="entity">The entity that was found</param>
/// <returns>True if the entity exists, false if it does not</returns>
bool TryGet(TKey key, out T entity);
/// <summary>
/// Returns true if the specified entity of type <typeparamref name="T"/> from the repository by the primary key exists
/// </summary>
/// <param name="key">The primary key.</param>
/// <param name="selector">The mapping selector that returns the result type.</param>
/// <param name="entity">The entity that was found</param>
/// <returns>True if the entity exists, false if it does not</returns>
bool TryGet<TResult>(TKey key, Expression<Func<T, TResult>> selector, out TResult entity);
/// <summary>
/// Deletes the specified entity by the primary key.
/// </summary>
/// <param name="key">The primary key.</param>
void Delete(TKey key);
/// <summary>
/// Deletes the specified entities by the primary keys provided.
/// </summary>
/// <param name="keys">The primary keys.</param>
void Delete(IEnumerable<TKey> keys);
/// <summary>
/// Deletes the specified entities by the primary keys provided.
/// </summary>
/// <param name="keys">The primary keys.</param>
void Delete(params TKey[] keys);
ICachingStrategy<T, TKey> CachingStrategy { get; set; }
/// <summary>
/// Used to get or set whether the cache is currently enabled and being used
/// </summary>
bool CachingEnabled { get; set; }
/// <summary>
/// Returns true if the cache was used on the very last query that was used (Get, Find, GetAll or FindAll)
/// </summary>
bool CacheUsed { get; }
/// <summary>
/// Disables caching for all code within the using() block it is called in
/// </summary>
/// <returns></returns>
IDisabledCache DisableCaching();
/// <summary>
/// Clears the cache for this particular repository. All other repositories will still have their caches available. Use Repository.ClearAllCache() to clear the cache for every repository
/// </summary>
void ClearCache();
string TraceInfo { get; }
TKey GetPrimaryKey(T entity);
}
}