Skip to content

Commit 6d881ff

Browse files
committed
Issue rsm-hcd#34 and rsm-hcd#17: Adding Read Async methods
1 parent dbaba31 commit 6d881ff

9 files changed

+826
-239
lines changed

src/Conductors/RepositoryConductor.cs

Lines changed: 25 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,8 @@ public partial class RepositoryConductor<T> : Conductor, IRepositoryConductor<T>
238238

239239
#region FindAll
240240

241-
/// <summary>
242-
/// Find all filtered, sorted and paged.
243-
/// </summary>
244-
/// <param name="filter">Filter to be used for querying.</param>
245-
/// <param name="orderBy">Properties that should be used for sorting.</param>
246-
/// <param name="includeProperties">Navigation properties that should be included.</param>
247-
/// <param name="skip">Number of entities that should be skipped.</param>
248-
/// <param name="take">Number of entities per page.</param>
249-
/// <param name="ignoreQueryFilters">If true, global query filters will be ignored for this query.</param>
250-
/// <param name="asNoTracking">Ignore change tracking on the result. Set <code>true</code> for read-only operations.</param>
251-
/// <returns>A queryable collection of entities for the given criteria.</returns>
241+
/// <inheritdoc />
242+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
252243
public virtual IResult<IQueryable<T>> FindAll(
253244
Expression<Func<T, bool>> filter = null,
254245
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
@@ -259,18 +250,8 @@ public virtual IResult<IQueryable<T>> FindAll(
259250
bool asNoTracking = false
260251
) => _readConductor.FindAll(filter, orderBy, includeProperties, skip, take, ignoreQueryFilters, asNoTracking);
261252

262-
/// <summary>
263-
/// Find all filtered, sorted and paged by grouping the result
264-
/// </summary>
265-
/// <param name="filter"></param>
266-
/// <param name="orderBy"></param>
267-
/// <param name="groupBy"></param>
268-
/// <param name="includeProperties"></param>
269-
/// <param name="skip"></param>
270-
/// <param name="take"></param>
271-
/// <param name="ignoreQueryFilters"></param>
272-
/// <param name="asNoTracking">Ignore change tracking on the result. Set <code>true</code> for read-only operations.</param>
273-
/// <returns></returns>
253+
/// <inheritdoc />
254+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
274255
public IResult<IQueryable<IGrouping<TKey, T>>> FindAll<TKey>(
275256
Expression<Func<T, bool>> filter = null,
276257
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
@@ -282,21 +263,8 @@ public IResult<IQueryable<IGrouping<TKey, T>>> FindAll<TKey>(
282263
bool asNoTracking = false
283264
) => _readConductor.FindAll(filter, orderBy, groupBy, includeProperties, skip, take, ignoreQueryFilters, asNoTracking);
284265

285-
/// <summary>
286-
/// Configure lazy loaded queryable, given provided parameters, to load a list of <typeparamref name="T"/>
287-
/// grouped by a <typeparamref name="TKey"/> and selected by groupBySelector tranformed into <typeparamref name="TResult"/>
288-
/// ref to: https://docs.microsoft.com/en-us/dotnet/api/system.linq.queryable.groupby?view=netcore-3.1#System_Linq_Queryable_GroupBy__3_System_Linq_IQueryable___0__System_Linq_Expressions_Expression_System_Func___0___1___System_Linq_Expressions_Expression_System_Func___1_System_Collections_Generic_IEnumerable___0____2___
289-
/// </summary>
290-
/// <param name="filter">Filter to be used for querying.</param>
291-
/// <param name="orderBy">Properties that should be used for sorting.</param>
292-
/// <param name="groupBy">Filter to be used for grouping by <typeparamref name="TKey"/> of <typeparamref name="T"/> .</param>
293-
/// <param name="groupBySelector">Selector to be used on groupBy used to create a result of <typeparamref name="TResult"/> value from each group.</param>
294-
/// <param name="includeProperties">Navigation properties that should be included.</param>
295-
/// <param name="skip">Number of entities that should be skipped.</param>
296-
/// <param name="take">Number of entities per page.</param>
297-
/// <param name="ignoreQueryFilters">If true, global query filters will be ignored for this query.</param>
298-
/// <param name="asNoTracking">Ignore change tracking on the result. Set <code>true</code> for read-only operations.</param>
299-
/// <returns></returns>
266+
/// <inheritdoc />
267+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
300268
public IResult<IQueryable<TResult>> FindAll<TKey, TResult>(
301269
Expression<Func<T, bool>> filter = null,
302270
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
@@ -308,18 +276,10 @@ public IResult<IQueryable<TResult>> FindAll<TKey, TResult>(
308276
bool? ignoreQueryFilters = false,
309277
bool asNoTracking = false
310278
) => _readConductor.FindAll(filter, orderBy, groupBy, groupBySelector, includeProperties, skip, take, ignoreQueryFilters, asNoTracking);
311-
312279

313-
/// <summary>
314-
/// Alternative FindAll for retrieving records using NextLinkParams in place of traditional
315-
/// determinate pagination mechanisms, such as; skip and take.
316-
/// </summary>
317-
/// <param name="nextLinkParams">Currently nothing is provided for NextLinkParams by this base class. Exists for overriding subclasses.</param>
318-
/// <param name="filter">Filter to be used for querying.</param>
319-
/// <param name="orderBy">Properties that should be used for sorting.</param>
320-
/// <param name="ignoreQueryFilters">If true, global query filters will be ignored for this query.</param>
321-
/// <param name="asNoTracking">Ignore change tracking on the result. Set <code>true</code> for read-only operations.</param>
322-
/// <returns>A queryable collection of entities for the given criteria.</returns>
280+
281+
/// <inheritdoc />
282+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
323283
public virtual IResult<IQueryable<T>> FindAll(
324284
Dictionary<string, string> nextLinkParams,
325285
Expression<Func<T, bool>> filter = null,
@@ -328,16 +288,8 @@ public virtual IResult<IQueryable<T>> FindAll(
328288
bool asNoTracking = false
329289
) => _readConductor.FindAll(nextLinkParams, filter, orderBy, ignoreQueryFilters, asNoTracking);
330290

331-
/// <summary>
332-
/// Similar to FindAll but loading the result into memory.
333-
/// </summary>
334-
/// <param name="filter">Filter to be used for querying.</param>
335-
/// <param name="orderBy">Properties that should be used for sorting.</param>
336-
/// <param name="includeProperties">Navigation properties that should be included.</param>
337-
/// <param name="skip">Number of entities that should be skipped.</param>
338-
/// <param name="take">Number of entities per page.</param>
339-
/// <param name="ignoreQueryFilters">If true, global query filters will be ignored for this query.</param>
340-
/// <returns>An in-memory collection of entities for the given criteria.</returns>
291+
/// <inheritdoc />
292+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
341293
public virtual IResult<IList<T>> FindAllCommitted(
342294
Expression<Func<T, bool>> filter = null,
343295
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
@@ -347,14 +299,8 @@ public virtual IResult<IList<T>> FindAllCommitted(
347299
bool? ignoreQueryFilters = false
348300
) => _readConductor.FindAllCommitted(filter, orderBy, includeProperties, skip, take, ignoreQueryFilters);
349301

350-
/// <summary>
351-
/// Similar to FindAll but loading the result into memory.
352-
/// </summary>
353-
/// <param name="nextLinkParams">Currently nothing is provided for NextLinkParams by this base class. Exists for overriding subclasses.</param>
354-
/// <param name="filter">Filter to be used for querying.</param>
355-
/// <param name="orderBy">Properties that should be used for sorting.</param>
356-
/// <param name="ignoreQueryFilters">If true, global query filters will be ignored for this query.</param>
357-
/// <returns>An in-memory collection of entities for the given criteria.</returns>
302+
/// <inheritdoc />
303+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
358304
public virtual IResult<IList<T>> FindAllCommitted(
359305
Dictionary<string, string> nextLinkParams,
360306
Expression<Func<T, bool>> filter = null,
@@ -366,52 +312,28 @@ public virtual IResult<IList<T>> FindAllCommitted(
366312

367313
#region FindById
368314

369-
/// <summary>
370-
/// Finds an entity by its Id.
371-
/// </summary>
372-
/// <param name="id">The entity identity value.</param>
373-
/// <returns>The entity with the provided identity value.</returns>
315+
/// <inheritdoc />
316+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
374317
public virtual IResult<T> FindById(long id) => _readConductor.FindById(id);
375318

376-
/// <summary>
377-
/// Finds an entity by its Id that also matches a filter.
378-
/// </summary>
379-
/// <param name="id">The entity identity value.</param>
380-
/// <param name="filter">Filter to be used for querying.</param>
381-
/// <returns>The entity with the provided identity value and filter condition met.</returns>
319+
/// <inheritdoc />
320+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
382321
public virtual IResult<T> FindById(long id, Expression<Func<T, bool>> filter) => _readConductor.FindById(id, filter);
383322

384-
/// <summary>
385-
/// Finds an entity by its Id.
386-
/// </summary>
387-
/// <param name="id">The entity identity value.</param>
388-
/// <param name="includeProperties">Navigation properties that should be included.</param>
389-
/// <returns>The entity with the provided identity value.</returns>
323+
/// <inheritdoc />
324+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
390325
public virtual IResult<T> FindById(long id, params Expression<Func<T, object>>[] includeProperties) => _readConductor.FindById(id, includeProperties);
391326

392-
/// <summary>
393-
/// Finds an entity by its Id.
394-
/// </summary>
395-
/// <param name="id">The entity identity value.</param>
396-
/// <param name="ignoreQueryFilters">If true, global query filters will be ignored for this query.</param>
397-
/// <param name="includeProperties">Navigation properties that should be included.</param>
398-
/// <returns>The entity with the provided identity value.</returns>
327+
/// <inheritdoc />
328+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
399329
public virtual IResult<T> FindById(long id, bool ignoreQueryFilters, params Expression<Func<T, object>>[] includeProperties) => _readConductor.FindById(id, ignoreQueryFilters, includeProperties);
400330

401-
/// <summary>
402-
/// Finds an entity by its Id.
403-
/// </summary>
404-
/// <param name="id">The entity identity value.</param>
405-
/// <param name="includeProperties">Navigation properties that should be included.</param>
406-
/// <returns>The entity with the provided identity value.</returns>
331+
/// <inheritdoc />
332+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
407333
public IResult<T> FindById(long id, params string[] includeProperties) => _readConductor.FindById(id, includeProperties);
408334

409-
/// <summary>
410-
/// Finds an entity by its Id.
411-
/// </summary>
412-
/// <param name="id">The entity identity value.</param>
413-
/// <param name="includeProperties">Navigation property that should be included.</param>
414-
/// <returns>The entity with the provided identity value.</returns>
335+
/// <inheritdoc />
336+
[Obsolete("This method is deprecated in favor of its async counter part", false)]
415337
public IResult<T> FindById(long id, string includeProperties) => _readConductor.FindById(id, includeProperties);
416338

417339
#endregion FindById

src/Conductors/RepositoryConductorAsync.cs

Lines changed: 155 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Linq.Expressions;
25
using System.Threading;
36
using System.Threading.Tasks;
47
using AndcultureCode.CSharp.Core.Interfaces;
@@ -138,5 +141,156 @@ public Task<IResult<bool>> RestoreAsync(long id, CancellationToken cancellationT
138141
_updateConductor.UpdateAsync(items, updatedBy, cancellationToken);
139142

140143
#endregion Update
144+
145+
#region Read
146+
147+
#region FindAll
148+
149+
/// <inheritdoc />
150+
public Task<IResult<IQueryable<T>>> FindAllAsync(
151+
Expression<Func<T, bool>> filter = null,
152+
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
153+
string includeProperties = null,
154+
int? skip = default(int?),
155+
int? take = default(int?),
156+
bool? ignoreQueryFilters = false,
157+
bool asNoTracking = false,
158+
CancellationToken cancellationToken = default
159+
) => _readConductor.FindAllAsync(
160+
filter,
161+
orderBy,
162+
includeProperties,
163+
skip,
164+
take,
165+
ignoreQueryFilters,
166+
asNoTracking,
167+
cancellationToken);
168+
169+
/// <inheritdoc />
170+
public Task<IResult<IQueryable<IGrouping<TKey, T>>>> FindAllAsync<TKey>(
171+
Expression<Func<T, bool>> filter = null,
172+
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
173+
Expression<Func<T, TKey>> groupBy = null,
174+
string includeProperties = null,
175+
int? skip = null,
176+
int? take = null,
177+
bool? ignoreQueryFilters = false,
178+
bool asNoTracking = false,
179+
CancellationToken cancellationToken = default
180+
) => _readConductor.FindAllAsync(
181+
filter,
182+
orderBy,
183+
groupBy,
184+
includeProperties,
185+
skip,
186+
take,
187+
ignoreQueryFilters,
188+
asNoTracking,
189+
cancellationToken);
190+
191+
/// <inheritdoc />
192+
public Task<IResult<IQueryable<TResult>>> FindAllAsync<TKey, TResult>(
193+
Expression<Func<T, bool>> filter = null,
194+
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
195+
Expression<Func<T, TKey>> groupBy = null,
196+
Expression<Func<TKey, IEnumerable<T>, TResult>> groupBySelector = null,
197+
string includeProperties = null,
198+
int? skip = default(int?),
199+
int? take = default(int?),
200+
bool? ignoreQueryFilters = false,
201+
bool asNoTracking = false,
202+
CancellationToken cancellationToken = default
203+
) => _readConductor.FindAllAsync(
204+
filter,
205+
orderBy,
206+
groupBy,
207+
groupBySelector,
208+
includeProperties,
209+
skip,
210+
take,
211+
ignoreQueryFilters,
212+
asNoTracking,
213+
cancellationToken);
214+
215+
216+
/// <inheritdoc />
217+
public Task<IResult<IQueryable<T>>> FindAllAsync(
218+
Dictionary<string, string> nextLinkParams,
219+
Expression<Func<T, bool>> filter = null,
220+
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
221+
bool? ignoreQueryFilters = false,
222+
bool asNoTracking = false,
223+
CancellationToken cancellationToken = default
224+
) => _readConductor.FindAllAsync(
225+
nextLinkParams,
226+
filter,
227+
orderBy,
228+
ignoreQueryFilters,
229+
asNoTracking,
230+
cancellationToken);
231+
232+
/// <inheritdoc />
233+
public Task<IResult<IList<T>>> FindAllCommittedAsync(
234+
Expression<Func<T, bool>> filter = null,
235+
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
236+
string includeProperties = null,
237+
int? skip = default(int?),
238+
int? take = default(int?),
239+
bool? ignoreQueryFilters = false,
240+
CancellationToken cancellationToken = default
241+
) => _readConductor.FindAllCommittedAsync(
242+
filter,
243+
orderBy,
244+
includeProperties,
245+
skip,
246+
take,
247+
ignoreQueryFilters,
248+
cancellationToken);
249+
250+
/// <inheritdoc />
251+
public Task<IResult<IList<T>>> FindAllCommittedAsync(
252+
Dictionary<string, string> nextLinkParams,
253+
Expression<Func<T, bool>> filter = null,
254+
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
255+
bool? ignoreQueryFilters = false,
256+
CancellationToken cancellationToken = default
257+
) => _readConductor.FindAllCommittedAsync(
258+
nextLinkParams,
259+
filter,
260+
orderBy,
261+
ignoreQueryFilters,
262+
cancellationToken);
263+
264+
#endregion FindAll
265+
266+
#region FindById
267+
268+
/// <inheritdoc />
269+
public Task<IResult<T>>FindByIdAsync(long id, bool ignoreQueryFilters = false, CancellationToken cancellationToken = default) =>
270+
_readConductor.FindByIdAsync(id, ignoreQueryFilters, cancellationToken);
271+
272+
/// <inheritdoc />
273+
public Task<IResult<T>> FindByIdAsync(long id, Expression<Func<T, bool>> filter, CancellationToken cancellationToken = default) =>
274+
_readConductor.FindByIdAsync(id, filter, cancellationToken);
275+
276+
/// <inheritdoc />
277+
public Task<IResult<T>> FindByIdAsync(long id, CancellationToken cancellationToken = default, params Expression<Func<T, object>>[] includeProperties) =>
278+
_readConductor.FindByIdAsync(id, cancellationToken, includeProperties);
279+
280+
/// <inheritdoc />
281+
public Task<IResult<T>> FindByIdAsync(long id, bool ignoreQueryFilters, CancellationToken cancellationToken = default, params Expression<Func<T, object>>[] includeProperties) =>
282+
_readConductor.FindByIdAsync(id, ignoreQueryFilters, cancellationToken, includeProperties);
283+
284+
/// <inheritdoc />
285+
public Task<IResult<T>> FindByIdAsync(long id, CancellationToken cancellationToken = default, params string[] includeProperties) =>
286+
_readConductor.FindByIdAsync(id, cancellationToken, includeProperties);
287+
288+
/// <inheritdoc />
289+
public Task<IResult<T>> FindByIdAsync(long id, string includeProperties, CancellationToken cancellationToken = default) =>
290+
_readConductor.FindByIdAsync(id, cancellationToken, includeProperties);
291+
292+
#endregion FindById
293+
294+
#endregion Read
141295
}
142296
}

0 commit comments

Comments
 (0)