@@ -18,12 +18,12 @@ namespace JsonApiDotNetCore.Data
1818 /// Provides a default repository implementation and is responsible for
1919 /// abstracting any EF Core APIs away from the service layer.
2020 /// </summary>
21- public class DefaultResourceRepository < TEntity , TId > : IResourceRepository < TEntity , TId >
22- where TEntity : class , IIdentifiable < TId >
21+ public class DefaultResourceRepository < TResource , TId > : IResourceRepository < TResource , TId >
22+ where TResource : class , IIdentifiable < TId >
2323 {
2424 private readonly ITargetedFields _targetedFields ;
2525 private readonly DbContext _context ;
26- private readonly DbSet < TEntity > _dbSet ;
26+ private readonly DbSet < TResource > _dbSet ;
2727 private readonly IResourceGraph _resourceGraph ;
2828 private readonly IGenericProcessorFactory _genericProcessorFactory ;
2929
@@ -46,16 +46,16 @@ public DefaultResourceRepository(
4646 _resourceGraph = resourceGraph ;
4747 _genericProcessorFactory = genericProcessorFactory ;
4848 _context = contextResolver . GetContext ( ) ;
49- _dbSet = _context . Set < TEntity > ( ) ;
49+ _dbSet = _context . Set < TResource > ( ) ;
5050 }
5151
5252 /// <inheritdoc />
53- public virtual IQueryable < TEntity > Get ( ) => _dbSet ;
53+ public virtual IQueryable < TResource > Get ( ) => _dbSet ;
5454 /// <inheritdoc />
55- public virtual IQueryable < TEntity > Get ( TId id ) => _dbSet . Where ( e => e . Id . Equals ( id ) ) ;
55+ public virtual IQueryable < TResource > Get ( TId id ) => _dbSet . Where ( e => e . Id . Equals ( id ) ) ;
5656
5757 /// <inheritdoc />
58- public virtual IQueryable < TEntity > Select ( IQueryable < TEntity > entities , List < AttrAttribute > fields )
58+ public virtual IQueryable < TResource > Select ( IQueryable < TResource > entities , List < AttrAttribute > fields )
5959 {
6060 if ( fields ? . Count > 0 )
6161 return entities . Select ( fields ) ;
@@ -64,24 +64,24 @@ public virtual IQueryable<TEntity> Select(IQueryable<TEntity> entities, List<Att
6464 }
6565
6666 /// <inheritdoc />
67- public virtual IQueryable < TEntity > Filter ( IQueryable < TEntity > entities , FilterQueryContext filterQueryContext )
67+ public virtual IQueryable < TResource > Filter ( IQueryable < TResource > entities , FilterQueryContext filterQueryContext )
6868 {
6969 if ( filterQueryContext . IsCustom )
7070 {
71- var query = ( Func < IQueryable < TEntity > , FilterQuery , IQueryable < TEntity > > ) filterQueryContext . CustomQuery ;
71+ var query = ( Func < IQueryable < TResource > , FilterQuery , IQueryable < TResource > > ) filterQueryContext . CustomQuery ;
7272 return query ( entities , filterQueryContext . Query ) ;
7373 }
7474 return entities . Filter ( filterQueryContext ) ;
7575 }
7676
7777 /// <inheritdoc />
78- public virtual IQueryable < TEntity > Sort ( IQueryable < TEntity > entities , SortQueryContext sortQueryContext )
78+ public virtual IQueryable < TResource > Sort ( IQueryable < TResource > entities , SortQueryContext sortQueryContext )
7979 {
8080 return entities . Sort ( sortQueryContext ) ;
8181 }
8282
8383 /// <inheritdoc />
84- public virtual async Task < TEntity > CreateAsync ( TEntity entity )
84+ public virtual async Task < TResource > CreateAsync ( TResource entity )
8585 {
8686 foreach ( var relationshipAttr in _targetedFields . Relationships )
8787 {
@@ -150,7 +150,7 @@ private bool IsHasOneRelationship(string internalRelationshipName, Type type)
150150 return ! type . GetProperty ( internalRelationshipName ) . PropertyType . Inherits ( typeof ( IEnumerable ) ) ;
151151 }
152152
153- private void DetachRelationships ( TEntity entity )
153+ private void DetachRelationships ( TResource entity )
154154 {
155155 foreach ( var relationshipAttr in _targetedFields . Relationships )
156156 {
@@ -176,7 +176,7 @@ private void DetachRelationships(TEntity entity)
176176 }
177177
178178 /// <inheritdoc />
179- public virtual async Task < TEntity > UpdateAsync ( TEntity updatedEntity )
179+ public virtual async Task < TResource > UpdateAsync ( TResource updatedEntity )
180180 {
181181 var databaseEntity = await Get ( updatedEntity . Id ) . FirstOrDefaultAsync ( ) ;
182182 if ( databaseEntity == null )
@@ -212,7 +212,7 @@ public virtual async Task<TEntity> UpdateAsync(TEntity updatedEntity)
212212 /// to the change tracker. It does so by checking if there already are
213213 /// instances of the to-be-attached entities in the change tracker.
214214 /// </summary>
215- private object GetTrackedRelationshipValue ( RelationshipAttribute relationshipAttr , TEntity entity , out bool wasAlreadyAttached )
215+ private object GetTrackedRelationshipValue ( RelationshipAttribute relationshipAttr , TResource entity , out bool wasAlreadyAttached )
216216 {
217217 wasAlreadyAttached = false ;
218218 if ( relationshipAttr is HasOneAttribute hasOneAttr )
@@ -278,7 +278,7 @@ public virtual async Task<bool> DeleteAsync(TId id)
278278 return true ;
279279 }
280280
281- public virtual IQueryable < TEntity > Include ( IQueryable < TEntity > entities , params RelationshipAttribute [ ] inclusionChain )
281+ public virtual IQueryable < TResource > Include ( IQueryable < TResource > entities , params RelationshipAttribute [ ] inclusionChain )
282282 {
283283 if ( ! inclusionChain . Any ( ) )
284284 return entities ;
@@ -293,7 +293,7 @@ public virtual IQueryable<TEntity> Include(IQueryable<TEntity> entities, params
293293 }
294294
295295 /// <inheritdoc />
296- public virtual async Task < IEnumerable < TEntity > > PageAsync ( IQueryable < TEntity > entities , int pageSize , int pageNumber )
296+ public virtual async Task < IEnumerable < TResource > > PageAsync ( IQueryable < TResource > entities , int pageSize , int pageNumber )
297297 {
298298 if ( pageNumber >= 0 )
299299 {
@@ -315,25 +315,25 @@ public virtual async Task<IEnumerable<TEntity>> PageAsync(IQueryable<TEntity> en
315315 }
316316
317317 /// <inheritdoc />
318- public async Task < int > CountAsync ( IQueryable < TEntity > entities )
318+ public async Task < int > CountAsync ( IQueryable < TResource > entities )
319319 {
320- return ( entities is IAsyncEnumerable < TEntity > )
320+ return ( entities is IAsyncEnumerable < TResource > )
321321 ? await entities . CountAsync ( )
322322 : entities . Count ( ) ;
323323 }
324324
325325 /// <inheritdoc />
326- public async Task < TEntity > FirstOrDefaultAsync ( IQueryable < TEntity > entities )
326+ public async Task < TResource > FirstOrDefaultAsync ( IQueryable < TResource > entities )
327327 {
328- return ( entities is IAsyncEnumerable < TEntity > )
328+ return ( entities is IAsyncEnumerable < TResource > )
329329 ? await entities . FirstOrDefaultAsync ( )
330330 : entities . FirstOrDefault ( ) ;
331331 }
332332
333333 /// <inheritdoc />
334- public async Task < IReadOnlyList < TEntity > > ToListAsync ( IQueryable < TEntity > entities )
334+ public async Task < IReadOnlyList < TResource > > ToListAsync ( IQueryable < TResource > entities )
335335 {
336- return ( entities is IAsyncEnumerable < TEntity > )
336+ return ( entities is IAsyncEnumerable < TResource > )
337337 ? await entities . ToListAsync ( )
338338 : entities . ToList ( ) ;
339339 }
@@ -351,7 +351,7 @@ public async Task<IReadOnlyList<TEntity>> ToListAsync(IQueryable<TEntity> entiti
351351 /// after which the reassignment `p1.todoItems = [t3, t4]` will actually
352352 /// make EF Core perform a complete replace. This method does the loading of `[t1, t2]`.
353353 /// </summary>
354- protected void LoadCurrentRelationships ( TEntity oldEntity , RelationshipAttribute relationshipAttribute )
354+ protected void LoadCurrentRelationships ( TResource oldEntity , RelationshipAttribute relationshipAttribute )
355355 {
356356 if ( relationshipAttribute is HasManyThroughAttribute throughAttribute )
357357 {
@@ -369,7 +369,7 @@ protected void LoadCurrentRelationships(TEntity oldEntity, RelationshipAttribute
369369 /// use the join table (ArticleTags). This methods assigns the relationship value to entity
370370 /// by taking care of that
371371 /// </summary>
372- private void AssignHasManyThrough ( TEntity entity , HasManyThroughAttribute hasManyThrough , IList relationshipValue )
372+ private void AssignHasManyThrough ( TResource entity , HasManyThroughAttribute hasManyThrough , IList relationshipValue )
373373 {
374374 var pointers = relationshipValue . Cast < IIdentifiable > ( ) ;
375375 var throughRelationshipCollection = Activator . CreateInstance ( hasManyThrough . ThroughProperty . PropertyType ) as IList ;
@@ -414,8 +414,8 @@ private IIdentifiable AttachOrGetTracked(IIdentifiable relationshipValue)
414414 }
415415
416416 /// <inheritdoc />
417- public class DefaultResourceRepository < TEntity > : DefaultResourceRepository < TEntity , int > , IResourceRepository < TEntity >
418- where TEntity : class , IIdentifiable < int >
417+ public class DefaultResourceRepository < TResource > : DefaultResourceRepository < TResource , int > , IResourceRepository < TResource >
418+ where TResource : class , IIdentifiable < int >
419419 {
420420 public DefaultResourceRepository ( ITargetedFields targetedFields ,
421421 IDbContextResolver contextResolver ,
0 commit comments