Skip to content

Commit b0ccc22

Browse files
Merge pull request #475 from johelvisguzman/query-result
Removed the IQueryResult and introduced a new cache query result interface for caching
2 parents 2225c53 + 65662af commit b0ccc22

File tree

27 files changed

+813
-652
lines changed

27 files changed

+813
-652
lines changed

src/DotNetToolkit.Repository.AdoNet/Internal/AdoNetRepositoryContext.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private async Task ExecuteSchemaValidateAsync(Type entityType, CancellationToken
202202
/// <param name="parameters">The parameters to apply to the SQL query string.</param>
203203
/// <param name="projector">A function to project each entity into a new form.</param>
204204
/// <returns>A list which each entity has been projected into a new form.</returns>
205-
public IQueryResult<IEnumerable<TEntity>> ExecuteSqlQuery<TEntity>(string sql, CommandType cmdType, Dictionary<string, object> parameters, Func<IDataReader, TEntity> projector) where TEntity : class
205+
public IEnumerable<TEntity> ExecuteSqlQuery<TEntity>(string sql, CommandType cmdType, Dictionary<string, object> parameters, Func<IDataReader, TEntity> projector) where TEntity : class
206206
{
207207
Guard.NotEmpty(sql, nameof(sql));
208208
Guard.NotNull(projector, nameof(projector));
@@ -216,7 +216,7 @@ public IQueryResult<IEnumerable<TEntity>> ExecuteSqlQuery<TEntity>(string sql, C
216216
list.Add(projector(reader));
217217
}
218218

219-
return new QueryResult<IEnumerable<TEntity>>(list);
219+
return list;
220220
}
221221
}
222222

@@ -227,11 +227,11 @@ public IQueryResult<IEnumerable<TEntity>> ExecuteSqlQuery<TEntity>(string sql, C
227227
/// <param name="cmdType">The command type.</param>
228228
/// <param name="parameters">The parameters to apply to the SQL query string.</param>
229229
/// <returns>The number of rows affected.</returns>
230-
public IQueryResult<int> ExecuteSqlCommand(string sql, CommandType cmdType, Dictionary<string, object> parameters)
230+
public int ExecuteSqlCommand(string sql, CommandType cmdType, Dictionary<string, object> parameters)
231231
{
232232
Guard.NotEmpty(sql, nameof(sql));
233233

234-
return new QueryResult<int>(_dbHelper.ExecuteNonQuery(sql, cmdType, parameters));
234+
return _dbHelper.ExecuteNonQuery(sql, cmdType, parameters);
235235
}
236236

237237
/// <summary>
@@ -378,7 +378,7 @@ public int SaveChanges()
378378
/// <param name="fetchStrategy">Defines the child objects that should be retrieved when loading the entity.</param>
379379
/// <param name="keyValues">The values of the primary key for the entity to be found.</param>
380380
/// <returns>The entity found in the repository.</returns>
381-
public IQueryResult<TEntity> Find<TEntity>(IFetchQueryStrategy<TEntity> fetchStrategy, params object[] keyValues) where TEntity : class
381+
public TEntity Find<TEntity>(IFetchQueryStrategy<TEntity> fetchStrategy, params object[] keyValues) where TEntity : class
382382
{
383383
Guard.NotEmpty(keyValues, nameof(keyValues));
384384

@@ -414,7 +414,7 @@ public IQueryResult<TEntity> Find<TEntity>(IFetchQueryStrategy<TEntity> fetchStr
414414
/// <param name="options">The options to apply to the query.</param>
415415
/// <param name="selector">A function to project each entity into a new form.</param>
416416
/// <returns>The projected entity result that satisfied the criteria specified by the <paramref name="selector" /> in the repository.</returns>
417-
public IQueryResult<TResult> Find<TEntity, TResult>(IQueryOptions<TEntity> options, Expression<Func<TEntity, TResult>> selector) where TEntity : class
417+
public TResult Find<TEntity, TResult>(IQueryOptions<TEntity> options, Expression<Func<TEntity, TResult>> selector) where TEntity : class
418418
{
419419
Guard.NotNull(selector, nameof(selector));
420420

@@ -470,15 +470,15 @@ public IPagedQueryResult<IEnumerable<TResult>> FindAll<TEntity, TResult>(IQueryO
470470
/// <typeparam name="TEntity">The type of the of the entity.</typeparam>
471471
/// <param name="options">The options to apply to the query.</param>
472472
/// <returns>The number of entities that satisfied the criteria specified by the <paramref name="options" /> in the repository.</returns>
473-
public IQueryResult<int> Count<TEntity>(IQueryOptions<TEntity> options) where TEntity : class
473+
public int Count<TEntity>(IQueryOptions<TEntity> options) where TEntity : class
474474
{
475475
QueryBuilder.CreateSelectStatement<TEntity>(Conventions, options, "COUNT(*)", out var sql, out var parameters);
476476

477477
ExecuteSchemaValidate(typeof(TEntity));
478478

479479
var result = _dbHelper.ExecuteScalar<int>(sql, parameters);
480480

481-
return new QueryResult<int>(result);
481+
return result;
482482
}
483483

484484
/// <summary>
@@ -487,7 +487,7 @@ public IQueryResult<int> Count<TEntity>(IQueryOptions<TEntity> options) where TE
487487
/// <typeparam name="TEntity">The type of the of the entity.</typeparam>
488488
/// <param name="options">The options to apply to the query.</param>
489489
/// <returns><c>true</c> if the repository contains one or more elements that match the conditions defined by the specified criteria; otherwise, <c>false</c>.</returns>
490-
public IQueryResult<bool> Exists<TEntity>(IQueryOptions<TEntity> options) where TEntity : class
490+
public bool Exists<TEntity>(IQueryOptions<TEntity> options) where TEntity : class
491491
{
492492
Guard.NotNull(options, nameof(options));
493493

@@ -506,7 +506,7 @@ public IQueryResult<bool> Exists<TEntity>(IQueryOptions<TEntity> options) where
506506
break;
507507
}
508508

509-
return new QueryResult<bool>(hasRows);
509+
return hasRows;
510510
}
511511
}
512512

@@ -612,7 +612,7 @@ public IPagedQueryResult<IEnumerable<TResult>> GroupBy<TEntity, TGroupKey, TResu
612612
/// <param name="projector">A function to project each entity into a new form.</param>
613613
/// <param name="cancellationToken">A <see cref="System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
614614
/// <returns>The <see cref="System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing a list which each entity has been projected into a new form.</returns>
615-
public async Task<IQueryResult<IEnumerable<TEntity>>> ExecuteSqlQueryAsync<TEntity>(string sql, CommandType cmdType, Dictionary<string, object> parameters, Func<IDataReader, TEntity> projector, CancellationToken cancellationToken = new CancellationToken()) where TEntity : class
615+
public async Task<IEnumerable<TEntity>> ExecuteSqlQueryAsync<TEntity>(string sql, CommandType cmdType, Dictionary<string, object> parameters, Func<IDataReader, TEntity> projector, CancellationToken cancellationToken = new CancellationToken()) where TEntity : class
616616
{
617617
Guard.NotEmpty(sql, nameof(sql));
618618
Guard.NotNull(projector, nameof(projector));
@@ -626,7 +626,7 @@ public IPagedQueryResult<IEnumerable<TResult>> GroupBy<TEntity, TGroupKey, TResu
626626
list.Add(projector(reader));
627627
}
628628

629-
return new QueryResult<IEnumerable<TEntity>>(list);
629+
return list;
630630
}
631631
}
632632

@@ -638,11 +638,11 @@ public IPagedQueryResult<IEnumerable<TResult>> GroupBy<TEntity, TGroupKey, TResu
638638
/// <param name="parameters">The parameters to apply to the SQL query string.</param>
639639
/// <param name="cancellationToken">A <see cref="System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
640640
/// <returns>The <see cref="System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing the number of rows affected.</returns>
641-
public async Task<IQueryResult<int>> ExecuteSqlCommandAsync(string sql, CommandType cmdType, Dictionary<string, object> parameters, CancellationToken cancellationToken = new CancellationToken())
641+
public async Task<int> ExecuteSqlCommandAsync(string sql, CommandType cmdType, Dictionary<string, object> parameters, CancellationToken cancellationToken = new CancellationToken())
642642
{
643643
Guard.NotEmpty(sql, nameof(sql));
644644

645-
return new QueryResult<int>(await _dbHelper.ExecuteNonQueryAsync(sql, cmdType, parameters, cancellationToken));
645+
return await _dbHelper.ExecuteNonQueryAsync(sql, cmdType, parameters, cancellationToken);
646646
}
647647

648648
/// <summary>
@@ -742,7 +742,7 @@ public IPagedQueryResult<IEnumerable<TResult>> GroupBy<TEntity, TGroupKey, TResu
742742
/// <param name="fetchStrategy">Defines the child objects that should be retrieved when loading the entity.</param>
743743
/// <param name="keyValues">The values of the primary key for the entity to be found.</param>
744744
/// <returns>The <see cref="T:System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing the entity found in the repository.</returns>
745-
public async Task<IQueryResult<TEntity>> FindAsync<TEntity>(CancellationToken cancellationToken, IFetchQueryStrategy<TEntity> fetchStrategy, params object[] keyValues) where TEntity : class
745+
public async Task<TEntity> FindAsync<TEntity>(CancellationToken cancellationToken, IFetchQueryStrategy<TEntity> fetchStrategy, params object[] keyValues) where TEntity : class
746746
{
747747
Guard.NotEmpty(keyValues, nameof(keyValues));
748748

@@ -779,7 +779,7 @@ public async Task<IQueryResult<TEntity>> FindAsync<TEntity>(CancellationToken ca
779779
/// <param name="selector">A function to project each entity into a new form.</param>
780780
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
781781
/// <returns>The <see cref="T:System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing the projected entity result that satisfied the criteria specified by the <paramref name="selector" /> in the repository.</returns>
782-
public async Task<IQueryResult<TResult>> FindAsync<TEntity, TResult>(IQueryOptions<TEntity> options, Expression<Func<TEntity, TResult>> selector, CancellationToken cancellationToken = new CancellationToken()) where TEntity : class
782+
public async Task<TResult> FindAsync<TEntity, TResult>(IQueryOptions<TEntity> options, Expression<Func<TEntity, TResult>> selector, CancellationToken cancellationToken = new CancellationToken()) where TEntity : class
783783
{
784784
Guard.NotNull(selector, nameof(selector));
785785

@@ -837,15 +837,15 @@ public async Task<IQueryResult<TEntity>> FindAsync<TEntity>(CancellationToken ca
837837
/// <param name="options">The options to apply to the query.</param>
838838
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
839839
/// <returns>The <see cref="T:System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing the number of entities that satisfied the criteria specified by the <paramref name="options" /> in the repository.</returns>
840-
public async Task<IQueryResult<int>> CountAsync<TEntity>(IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken()) where TEntity : class
840+
public async Task<int> CountAsync<TEntity>(IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken()) where TEntity : class
841841
{
842842
QueryBuilder.CreateSelectStatement<TEntity>(Conventions, options, "COUNT(*)", out var sql, out var parameters);
843843

844844
ExecuteSchemaValidate(typeof(TEntity));
845845

846846
var result = await _dbHelper.ExecuteScalarAsync<int>(sql, parameters, cancellationToken);
847847

848-
return new QueryResult<int>(result);
848+
return result;
849849
}
850850

851851
/// <summary>
@@ -855,7 +855,7 @@ public async Task<IQueryResult<TEntity>> FindAsync<TEntity>(CancellationToken ca
855855
/// <param name="options">The options to apply to the query.</param>
856856
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
857857
/// <returns>The <see cref="T:System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing a value indicating <c>true</c> if the repository contains one or more elements that match the conditions defined by the specified criteria; otherwise, <c>false</c>.</returns>
858-
public async Task<IQueryResult<bool>> ExistsAsync<TEntity>(IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken()) where TEntity : class
858+
public async Task<bool> ExistsAsync<TEntity>(IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken()) where TEntity : class
859859
{
860860
Guard.NotNull(options, nameof(options));
861861

@@ -874,7 +874,7 @@ public async Task<IQueryResult<TEntity>> FindAsync<TEntity>(CancellationToken ca
874874
break;
875875
}
876876

877-
return new QueryResult<bool>(hasRows);
877+
return hasRows;
878878
}
879879
}
880880

0 commit comments

Comments
 (0)