Skip to content

Commit 796c5ef

Browse files
Add a GroupBy function to the ICanAggregate trait
1 parent 37c98ea commit 796c5ef

File tree

4 files changed

+101
-189
lines changed

4 files changed

+101
-189
lines changed

src/DotNetToolkit.Repository/RepositoryAsyncBase.cs

Lines changed: 4 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,6 @@ public abstract class RepositoryAsyncBase<TEntity, TKey> : RepositoryBase<TEntit
118118
return CountAsync(new Specification<TEntity>(predicate), cancellationToken);
119119
}
120120

121-
/// <summary>
122-
/// Asynchronously returns a new <see cref="Dictionary{TDictionaryKey, TEntity}" /> according to the specified <paramref name="keySelector" />.
123-
/// </summary>
124-
/// <typeparam name="TDictionaryKey">The type of the dictionary key.</typeparam>
125-
/// <param name="keySelector">A function to extract a key from each entity.</param>
126-
/// <param name="cancellationToken">A <see cref="System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
127-
/// <returns>The <see cref="System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing a new <see cref="Dictionary{TDictionaryKey, TEntity}" /> that contains keys and values.</returns>
128-
public Task<Dictionary<TDictionaryKey, TEntity>> ToDictionaryAsync<TDictionaryKey>(Func<TEntity, TDictionaryKey> keySelector, CancellationToken cancellationToken = new CancellationToken())
129-
{
130-
if (keySelector == null)
131-
throw new ArgumentNullException(nameof(keySelector));
132-
133-
return ToDictionaryAsync(keySelector, (IQueryOptions<TEntity>)null, cancellationToken);
134-
}
135-
136121
/// <summary>
137122
/// Asynchronously returns a new <see cref="Dictionary{TDictionaryKey, TEntity}" /> according to the specified <paramref name="keySelector" />.
138123
/// </summary>
@@ -141,31 +126,14 @@ public abstract class RepositoryAsyncBase<TEntity, TKey> : RepositoryBase<TEntit
141126
/// <param name="options">The options to apply to the query.</param>
142127
/// <param name="cancellationToken">A <see cref="System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
143128
/// <returns>The <see cref="System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing a new <see cref="Dictionary{TDictionaryKey, TEntity}" /> that contains keys and values.</returns>
144-
public Task<Dictionary<TDictionaryKey, TEntity>> ToDictionaryAsync<TDictionaryKey>(Func<TEntity, TDictionaryKey> keySelector, IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken())
129+
public Task<Dictionary<TDictionaryKey, TEntity>> ToDictionaryAsync<TDictionaryKey>(Func<TEntity, TDictionaryKey> keySelector, IQueryOptions<TEntity> options = null, CancellationToken cancellationToken = new CancellationToken())
145130
{
146131
if (keySelector == null)
147132
throw new ArgumentNullException(nameof(keySelector));
148133

149134
return ToDictionaryAsync((ISpecification<TEntity>)null, keySelector, options, cancellationToken);
150135
}
151136

152-
/// <summary>
153-
/// Asynchronously returns a new <see cref="Dictionary{TDictionaryKey, TElemen}" /> according to the specified <paramref name="keySelector" />, a comparer, and an element selector function..
154-
/// </summary>
155-
/// <typeparam name="TDictionaryKey">The type of the dictionary key.</typeparam>
156-
/// <typeparam name="TElement">The type of the value returned by elementSelector.</typeparam>
157-
/// <param name="keySelector">A function to extract a key from each entity.</param>
158-
/// <param name="elementSelector">A transform function to produce a result element value from each element.</param>
159-
/// <param name="cancellationToken">A <see cref="System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
160-
/// <returns>The <see cref="System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing a new <see cref="Dictionary{TDictionaryKey, TEntity}" /> that contains keys and values.</returns>
161-
public Task<Dictionary<TDictionaryKey, TElement>> ToDictionaryAsync<TDictionaryKey, TElement>(Func<TEntity, TDictionaryKey> keySelector, Func<TEntity, TElement> elementSelector, CancellationToken cancellationToken = new CancellationToken())
162-
{
163-
if (keySelector == null)
164-
throw new ArgumentNullException(nameof(keySelector));
165-
166-
return ToDictionaryAsync(keySelector, elementSelector, (IQueryOptions<TEntity>)null, cancellationToken);
167-
}
168-
169137
/// <summary>
170138
/// Asynchronously returns a new <see cref="Dictionary{TDictionaryKey, TElemen}" /> according to the specified <paramref name="keySelector" />, a comparer, and an element selector function..
171139
/// </summary>
@@ -176,30 +144,14 @@ public abstract class RepositoryAsyncBase<TEntity, TKey> : RepositoryBase<TEntit
176144
/// <param name="options">The options to apply to the query.</param>
177145
/// <param name="cancellationToken">A <see cref="System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
178146
/// <returns>The <see cref="System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing a new <see cref="Dictionary{TDictionaryKey, TEntity}" /> that contains keys and values.</returns>
179-
public Task<Dictionary<TDictionaryKey, TElement>> ToDictionaryAsync<TDictionaryKey, TElement>(Func<TEntity, TDictionaryKey> keySelector, Func<TEntity, TElement> elementSelector, IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken())
147+
public Task<Dictionary<TDictionaryKey, TElement>> ToDictionaryAsync<TDictionaryKey, TElement>(Func<TEntity, TDictionaryKey> keySelector, Func<TEntity, TElement> elementSelector, IQueryOptions<TEntity> options = null, CancellationToken cancellationToken = new CancellationToken())
180148
{
181149
if (keySelector == null)
182150
throw new ArgumentNullException(nameof(keySelector));
183151

184152
return ToDictionaryAsync((ISpecification<TEntity>)null, keySelector, elementSelector, options, cancellationToken);
185153
}
186154

187-
/// <summary>
188-
/// Asynchronously returns a new <see cref="Dictionary{TDictionaryKey, TEntity}" /> according to the specified <paramref name="keySelector" />.
189-
/// </summary>
190-
/// <typeparam name="TDictionaryKey">The type of the dictionary key.</typeparam>
191-
/// <param name="criteria">The specification criteria that is used for matching entities against.</param>
192-
/// <param name="keySelector">A function to extract a key from each entity.</param>
193-
/// <param name="cancellationToken">A <see cref="System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
194-
/// <returns>The <see cref="System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing a new <see cref="Dictionary{TDictionaryKey, TEntity}" /> that contains keys and values.</returns>
195-
public Task<Dictionary<TDictionaryKey, TEntity>> ToDictionaryAsync<TDictionaryKey>(ISpecification<TEntity> criteria, Func<TEntity, TDictionaryKey> keySelector, CancellationToken cancellationToken = new CancellationToken())
196-
{
197-
if (keySelector == null)
198-
throw new ArgumentNullException(nameof(keySelector));
199-
200-
return ToDictionaryAsync(criteria, keySelector, (IQueryOptions<TEntity>)null, cancellationToken);
201-
}
202-
203155
/// <summary>
204156
/// Asynchronously returns a new <see cref="Dictionary{TDictionaryKey, TEntity}" /> according to the specified <paramref name="keySelector" />.
205157
/// </summary>
@@ -209,32 +161,14 @@ public abstract class RepositoryAsyncBase<TEntity, TKey> : RepositoryBase<TEntit
209161
/// <param name="options">The options to apply to the query.</param>
210162
/// <param name="cancellationToken">A <see cref="System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
211163
/// <returns>The <see cref="System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing a new <see cref="Dictionary{TDictionaryKey, TEntity}" /> that contains keys and values.</returns>
212-
public Task<Dictionary<TDictionaryKey, TEntity>> ToDictionaryAsync<TDictionaryKey>(ISpecification<TEntity> criteria, Func<TEntity, TDictionaryKey> keySelector, IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken())
164+
public Task<Dictionary<TDictionaryKey, TEntity>> ToDictionaryAsync<TDictionaryKey>(ISpecification<TEntity> criteria, Func<TEntity, TDictionaryKey> keySelector, IQueryOptions<TEntity> options = null, CancellationToken cancellationToken = new CancellationToken())
213165
{
214166
if (keySelector == null)
215167
throw new ArgumentNullException(nameof(keySelector));
216168

217169
return ToDictionaryAsync(criteria, keySelector, IdentityFunction<TEntity>.Instance, options, cancellationToken);
218170
}
219171

220-
/// <summary>
221-
/// Asynchronously returns a new <see cref="Dictionary{TDictionaryKey, TElemen}" /> according to the specified <paramref name="keySelector" />, a comparer, and an element selector function..
222-
/// </summary>
223-
/// <typeparam name="TDictionaryKey">The type of the dictionary key.</typeparam>
224-
/// <typeparam name="TElement">The type of the value returned by elementSelector.</typeparam>
225-
/// <param name="criteria">The specification criteria that is used for matching entities against.</param>
226-
/// <param name="keySelector">A function to extract a key from each entity.</param>
227-
/// <param name="elementSelector">A transform function to produce a result element value from each element.</param>
228-
/// <param name="cancellationToken">A <see cref="System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
229-
/// <returns>The <see cref="System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing a new <see cref="Dictionary{TDictionaryKey, TEntity}" /> that contains keys and values.</returns>
230-
public Task<Dictionary<TDictionaryKey, TElement>> ToDictionaryAsync<TDictionaryKey, TElement>(ISpecification<TEntity> criteria, Func<TEntity, TDictionaryKey> keySelector, Func<TEntity, TElement> elementSelector, CancellationToken cancellationToken = new CancellationToken())
231-
{
232-
if (keySelector == null)
233-
throw new ArgumentNullException(nameof(keySelector));
234-
235-
return ToDictionaryAsync(criteria, keySelector, elementSelector, (IQueryOptions<TEntity>)null, cancellationToken);
236-
}
237-
238172
/// <summary>
239173
/// Asynchronously returns a new <see cref="Dictionary{TDictionaryKey, TElemen}" /> according to the specified <paramref name="keySelector" />, a comparer, and an element selector function..
240174
/// </summary>
@@ -246,7 +180,7 @@ public abstract class RepositoryAsyncBase<TEntity, TKey> : RepositoryBase<TEntit
246180
/// <param name="options">The options to apply to the query.</param>
247181
/// <param name="cancellationToken">A <see cref="System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
248182
/// <returns>The <see cref="System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing a new <see cref="Dictionary{TDictionaryKey, TEntity}" /> that contains keys and values.</returns>
249-
public Task<Dictionary<TDictionaryKey, TElement>> ToDictionaryAsync<TDictionaryKey, TElement>(ISpecification<TEntity> criteria, Func<TEntity, TDictionaryKey> keySelector, Func<TEntity, TElement> elementSelector, IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken())
183+
public Task<Dictionary<TDictionaryKey, TElement>> ToDictionaryAsync<TDictionaryKey, TElement>(ISpecification<TEntity> criteria, Func<TEntity, TDictionaryKey> keySelector, Func<TEntity, TElement> elementSelector, IQueryOptions<TEntity> options = null, CancellationToken cancellationToken = new CancellationToken())
250184
{
251185
if (keySelector == null)
252186
throw new ArgumentNullException(nameof(keySelector));

0 commit comments

Comments
 (0)