Skip to content

Commit 8a9a1c0

Browse files
Merge pull request #100 from johelvisguzman/jaguzman
Consolidated some of the base entity methods in the repository class
2 parents 2bb2361 + 5f40688 commit 8a9a1c0

File tree

5 files changed

+17
-107
lines changed

5 files changed

+17
-107
lines changed

src/DotNetToolkit.Repository.AdoNet/AdoNetRepositoryBase.cs

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,19 +1793,6 @@ protected override TEntity GetEntity(TKey key, IFetchStrategy<TEntity> fetchStra
17931793
return ExecuteObject<TEntity>(config.Sql, config.Parameters, r => AutoMap(r, config));
17941794
}
17951795

1796-
/// <summary>
1797-
/// Gets an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
1798-
/// </summary>
1799-
protected override TEntity GetEntity(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options)
1800-
{
1801-
if (criteria == null)
1802-
throw new ArgumentNullException(nameof(criteria));
1803-
1804-
PrepareSelectStatement(criteria, options, out DbSqlSelectStatementConfig config);
1805-
1806-
return ExecuteObject<TEntity>(config.Sql, config.Parameters, r => AutoMap(r, config));
1807-
}
1808-
18091796
/// <summary>
18101797
/// Gets an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
18111798
/// </summary>
@@ -1822,16 +1809,6 @@ protected override TResult GetEntity<TResult>(ISpecification<TEntity> criteria,
18221809
return ExecuteObject<TResult>(config.Sql, config.Parameters, r => AutoMap<TResult>(r, selector, config));
18231810
}
18241811

1825-
/// <summary>
1826-
/// Gets a collection of entities that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
1827-
/// </summary>
1828-
protected override IEnumerable<TEntity> GetEntities(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options)
1829-
{
1830-
PrepareSelectStatement(criteria, options, out DbSqlSelectStatementConfig config);
1831-
1832-
return ExecuteList<TEntity>(config.Sql, config.Parameters, r => AutoMap(r, config));
1833-
}
1834-
18351812
/// <summary>
18361813
/// Gets a collection of entities that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
18371814
/// </summary>
@@ -1989,19 +1966,6 @@ public override void Dispose()
19891966
return ExecuteObjectAsync<TEntity>(config.Sql, config.Parameters, r => AutoMap(r, config), cancellationToken);
19901967
}
19911968

1992-
/// <summary>
1993-
/// A protected asynchronous overridable method for getting an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
1994-
/// </summary>
1995-
protected override Task<TEntity> GetEntityAsync(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken())
1996-
{
1997-
if (criteria == null)
1998-
throw new ArgumentNullException(nameof(criteria));
1999-
2000-
PrepareSelectStatement(criteria, options, out DbSqlSelectStatementConfig config);
2001-
2002-
return ExecuteObjectAsync<TEntity>(config.Sql, config.Parameters, r => AutoMap(r, config), cancellationToken);
2003-
}
2004-
20051969
/// <summary>
20061970
/// A protected asynchronous overridable method for getting an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
20071971
/// </summary>
@@ -2018,24 +1982,11 @@ public override void Dispose()
20181982
return ExecuteObjectAsync<TResult>(config.Sql, config.Parameters, r => AutoMap<TResult>(r, selector, config), cancellationToken);
20191983
}
20201984

2021-
/// <summary>
2022-
/// A protected asynchronous overridable method for getting a collection of entities that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
2023-
/// </summary>
2024-
protected override Task<IEnumerable<TEntity>> GetEntitiesAsync(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken())
2025-
{
2026-
PrepareSelectStatement(criteria, options, out DbSqlSelectStatementConfig config);
2027-
2028-
return ExecuteListAsync<TEntity>(config.Sql, config.Parameters, r => AutoMap(r, config), cancellationToken);
2029-
}
2030-
20311985
/// <summary>
20321986
/// A protected asynchronous overridable method for getting a collection of entities that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
20331987
/// </summary>
20341988
protected override Task<IEnumerable<TResult>> GetEntitiesAsync<TResult>(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, Expression<Func<TEntity, TResult>> selector, CancellationToken cancellationToken = new CancellationToken())
20351989
{
2036-
if (criteria == null)
2037-
throw new ArgumentNullException(nameof(criteria));
2038-
20391990
if (selector == null)
20401991
throw new ArgumentNullException(nameof(selector));
20411992

src/DotNetToolkit.Repository.EntityFramework/EfRepositoryBase.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,6 @@ public override void Dispose()
166166
return fetchStrategy == null ? DbSet.FindAsync(cancellationToken, key) : base.GetEntityAsync(key, fetchStrategy, cancellationToken);
167167
}
168168

169-
/// <summary>
170-
/// A protected asynchronous overridable method for getting an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
171-
/// </summary>
172-
protected override Task<TEntity> GetEntityAsync(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken())
173-
{
174-
if (criteria == null)
175-
throw new ArgumentNullException(nameof(criteria));
176-
177-
return GetQuery(criteria, options).FirstOrDefaultAsync(cancellationToken);
178-
}
179-
180169
/// <summary>
181170
/// A protected asynchronous overridable method for getting an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
182171
/// </summary>
@@ -191,22 +180,11 @@ public override void Dispose()
191180
return GetQuery(criteria, options).Select(selector).FirstOrDefaultAsync(cancellationToken);
192181
}
193182

194-
/// <summary>
195-
/// A protected asynchronous overridable method for getting a collection of entities that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
196-
/// </summary>
197-
protected override async Task<IEnumerable<TEntity>> GetEntitiesAsync(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken())
198-
{
199-
return await GetQuery(criteria, options).ToListAsync(cancellationToken);
200-
}
201-
202183
/// <summary>
203184
/// A protected asynchronous overridable method for getting a collection of entities that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
204185
/// </summary>
205186
protected override async Task<IEnumerable<TResult>> GetEntitiesAsync<TResult>(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, Expression<Func<TEntity, TResult>> selector, CancellationToken cancellationToken = new CancellationToken())
206187
{
207-
if (criteria == null)
208-
throw new ArgumentNullException(nameof(criteria));
209-
210188
if (selector == null)
211189
throw new ArgumentNullException(nameof(selector));
212190

src/DotNetToolkit.Repository.EntityFrameworkCore/EfCoreRepositoryBase.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,6 @@ public override void Dispose()
166166
return fetchStrategy == null ? DbSet.FindAsync(new object[] { key }, cancellationToken) : base.GetEntityAsync(key, fetchStrategy, cancellationToken);
167167
}
168168

169-
/// <summary>
170-
/// A protected asynchronous overridable method for getting an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
171-
/// </summary>
172-
protected override Task<TEntity> GetEntityAsync(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken())
173-
{
174-
if (criteria == null)
175-
throw new ArgumentNullException(nameof(criteria));
176-
177-
return GetQuery(criteria, options).FirstOrDefaultAsync(cancellationToken);
178-
}
179-
180169
/// <summary>
181170
/// A protected asynchronous overridable method for getting an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
182171
/// </summary>
@@ -191,22 +180,11 @@ public override void Dispose()
191180
return GetQuery(criteria, options).Select(selector).FirstOrDefaultAsync(cancellationToken);
192181
}
193182

194-
/// <summary>
195-
/// A protected asynchronous overridable method for getting a collection of entities that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
196-
/// </summary>
197-
protected override async Task<IEnumerable<TEntity>> GetEntitiesAsync(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken())
198-
{
199-
return await GetQuery(criteria, options).ToListAsync(cancellationToken);
200-
}
201-
202183
/// <summary>
203184
/// A protected asynchronous overridable method for getting a collection of entities that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
204185
/// </summary>
205186
protected override async Task<IEnumerable<TResult>> GetEntitiesAsync<TResult>(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, Expression<Func<TEntity, TResult>> selector, CancellationToken cancellationToken = new CancellationToken())
206187
{
207-
if (criteria == null)
208-
throw new ArgumentNullException(nameof(criteria));
209-
210188
if (selector == null)
211189
throw new ArgumentNullException(nameof(selector));
212190

src/DotNetToolkit.Repository/RepositoryBase.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,9 @@ protected TEntity GetEntity(TKey key)
179179
/// <summary>
180180
/// Gets an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
181181
/// </summary>
182-
protected virtual TEntity GetEntity(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options)
182+
protected TEntity GetEntity(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options)
183183
{
184-
if (criteria == null)
185-
throw new ArgumentNullException(nameof(criteria));
186-
187-
return GetQuery(criteria, options).FirstOrDefault();
184+
return GetEntity<TEntity>(criteria, options, IdentityExpression<TEntity>.Instance);
188185
}
189186

190187
/// <summary>
@@ -204,9 +201,9 @@ protected virtual TResult GetEntity<TResult>(ISpecification<TEntity> criteria, I
204201
/// <summary>
205202
/// Gets a collection of entities that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
206203
/// </summary>
207-
protected virtual IEnumerable<TEntity> GetEntities(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options)
204+
protected IEnumerable<TEntity> GetEntities(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options)
208205
{
209-
return GetQuery(criteria, options).ToList();
206+
return GetEntities<TEntity>(criteria, options, IdentityExpression<TEntity>.Instance);
210207
}
211208

212209
/// <summary>

src/DotNetToolkit.Repository/RepositoryBaseAsync.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,26 @@ protected RepositoryBaseAsync(IEnumerable<IRepositoryInterceptor> interceptors)
6969
}
7070

7171
/// <summary>
72-
/// A protected asynchronous overridable method for getting an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
72+
/// Asynchronously gets a collection of entities that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
7373
/// </summary>
74-
protected abstract Task<TEntity> GetEntityAsync(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken());
74+
protected Task<IEnumerable<TEntity>> GetEntitiesAsync(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken())
75+
{
76+
return GetEntitiesAsync<TEntity>(criteria, options, IdentityExpression<TEntity>.Instance, cancellationToken);
77+
}
7578

7679
/// <summary>
77-
/// A protected asynchronous overridable method for getting an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
80+
/// Asynchronously gets an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
7881
/// </summary>
79-
protected abstract Task<TResult> GetEntityAsync<TResult>(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, Expression<Func<TEntity, TResult>> selector, CancellationToken cancellationToken = new CancellationToken());
82+
protected Task<TEntity> GetEntityAsync(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken())
83+
{
84+
return GetEntityAsync<TEntity>(criteria, options, IdentityExpression<TEntity>.Instance, cancellationToken);
85+
}
8086

8187
/// <summary>
82-
/// A protected asynchronous overridable method for getting a collection of entities that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
88+
/// A protected asynchronous overridable method for getting an entity that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
8389
/// </summary>
84-
protected abstract Task<IEnumerable<TEntity>> GetEntitiesAsync(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, CancellationToken cancellationToken = new CancellationToken());
85-
90+
protected abstract Task<TResult> GetEntityAsync<TResult>(ISpecification<TEntity> criteria, IQueryOptions<TEntity> options, Expression<Func<TEntity, TResult>> selector, CancellationToken cancellationToken = new CancellationToken());
91+
8692
/// <summary>
8793
/// A protected asynchronous overridable method for getting a collection of entities that satisfies the criteria specified by the <paramref name="criteria" /> from the repository.
8894
/// </summary>

0 commit comments

Comments
 (0)