@@ -18,12 +18,12 @@ namespace JsonApiDotNetCore.Data
18
18
/// Provides a default repository implementation and is responsible for
19
19
/// abstracting any EF Core APIs away from the service layer.
20
20
/// </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 >
23
23
{
24
24
private readonly ITargetedFields _targetedFields ;
25
25
private readonly DbContext _context ;
26
- private readonly DbSet < TEntity > _dbSet ;
26
+ private readonly DbSet < TResource > _dbSet ;
27
27
private readonly IResourceGraph _resourceGraph ;
28
28
private readonly IGenericProcessorFactory _genericProcessorFactory ;
29
29
@@ -46,16 +46,16 @@ public DefaultResourceRepository(
46
46
_resourceGraph = resourceGraph ;
47
47
_genericProcessorFactory = genericProcessorFactory ;
48
48
_context = contextResolver . GetContext ( ) ;
49
- _dbSet = _context . Set < TEntity > ( ) ;
49
+ _dbSet = _context . Set < TResource > ( ) ;
50
50
}
51
51
52
52
/// <inheritdoc />
53
- public virtual IQueryable < TEntity > Get ( ) => _dbSet ;
53
+ public virtual IQueryable < TResource > Get ( ) => _dbSet ;
54
54
/// <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 ) ) ;
56
56
57
57
/// <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 )
59
59
{
60
60
if ( fields ? . Count > 0 )
61
61
return entities . Select ( fields ) ;
@@ -64,24 +64,24 @@ public virtual IQueryable<TEntity> Select(IQueryable<TEntity> entities, List<Att
64
64
}
65
65
66
66
/// <inheritdoc />
67
- public virtual IQueryable < TEntity > Filter ( IQueryable < TEntity > entities , FilterQueryContext filterQueryContext )
67
+ public virtual IQueryable < TResource > Filter ( IQueryable < TResource > entities , FilterQueryContext filterQueryContext )
68
68
{
69
69
if ( filterQueryContext . IsCustom )
70
70
{
71
- var query = ( Func < IQueryable < TEntity > , FilterQuery , IQueryable < TEntity > > ) filterQueryContext . CustomQuery ;
71
+ var query = ( Func < IQueryable < TResource > , FilterQuery , IQueryable < TResource > > ) filterQueryContext . CustomQuery ;
72
72
return query ( entities , filterQueryContext . Query ) ;
73
73
}
74
74
return entities . Filter ( filterQueryContext ) ;
75
75
}
76
76
77
77
/// <inheritdoc />
78
- public virtual IQueryable < TEntity > Sort ( IQueryable < TEntity > entities , SortQueryContext sortQueryContext )
78
+ public virtual IQueryable < TResource > Sort ( IQueryable < TResource > entities , SortQueryContext sortQueryContext )
79
79
{
80
80
return entities . Sort ( sortQueryContext ) ;
81
81
}
82
82
83
83
/// <inheritdoc />
84
- public virtual async Task < TEntity > CreateAsync ( TEntity entity )
84
+ public virtual async Task < TResource > CreateAsync ( TResource entity )
85
85
{
86
86
foreach ( var relationshipAttr in _targetedFields . Relationships )
87
87
{
@@ -150,7 +150,7 @@ private bool IsHasOneRelationship(string internalRelationshipName, Type type)
150
150
return ! type . GetProperty ( internalRelationshipName ) . PropertyType . Inherits ( typeof ( IEnumerable ) ) ;
151
151
}
152
152
153
- private void DetachRelationships ( TEntity entity )
153
+ private void DetachRelationships ( TResource entity )
154
154
{
155
155
foreach ( var relationshipAttr in _targetedFields . Relationships )
156
156
{
@@ -176,7 +176,7 @@ private void DetachRelationships(TEntity entity)
176
176
}
177
177
178
178
/// <inheritdoc />
179
- public virtual async Task < TEntity > UpdateAsync ( TEntity updatedEntity )
179
+ public virtual async Task < TResource > UpdateAsync ( TResource updatedEntity )
180
180
{
181
181
var databaseEntity = await Get ( updatedEntity . Id ) . FirstOrDefaultAsync ( ) ;
182
182
if ( databaseEntity == null )
@@ -212,7 +212,7 @@ public virtual async Task<TEntity> UpdateAsync(TEntity updatedEntity)
212
212
/// to the change tracker. It does so by checking if there already are
213
213
/// instances of the to-be-attached entities in the change tracker.
214
214
/// </summary>
215
- private object GetTrackedRelationshipValue ( RelationshipAttribute relationshipAttr , TEntity entity , out bool wasAlreadyAttached )
215
+ private object GetTrackedRelationshipValue ( RelationshipAttribute relationshipAttr , TResource entity , out bool wasAlreadyAttached )
216
216
{
217
217
wasAlreadyAttached = false ;
218
218
if ( relationshipAttr is HasOneAttribute hasOneAttr )
@@ -278,7 +278,7 @@ public virtual async Task<bool> DeleteAsync(TId id)
278
278
return true ;
279
279
}
280
280
281
- public virtual IQueryable < TEntity > Include ( IQueryable < TEntity > entities , params RelationshipAttribute [ ] inclusionChain )
281
+ public virtual IQueryable < TResource > Include ( IQueryable < TResource > entities , params RelationshipAttribute [ ] inclusionChain )
282
282
{
283
283
if ( ! inclusionChain . Any ( ) )
284
284
return entities ;
@@ -293,7 +293,7 @@ public virtual IQueryable<TEntity> Include(IQueryable<TEntity> entities, params
293
293
}
294
294
295
295
/// <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 )
297
297
{
298
298
if ( pageNumber >= 0 )
299
299
{
@@ -315,25 +315,25 @@ public virtual async Task<IEnumerable<TEntity>> PageAsync(IQueryable<TEntity> en
315
315
}
316
316
317
317
/// <inheritdoc />
318
- public async Task < int > CountAsync ( IQueryable < TEntity > entities )
318
+ public async Task < int > CountAsync ( IQueryable < TResource > entities )
319
319
{
320
- return ( entities is IAsyncEnumerable < TEntity > )
320
+ return ( entities is IAsyncEnumerable < TResource > )
321
321
? await entities . CountAsync ( )
322
322
: entities . Count ( ) ;
323
323
}
324
324
325
325
/// <inheritdoc />
326
- public async Task < TEntity > FirstOrDefaultAsync ( IQueryable < TEntity > entities )
326
+ public async Task < TResource > FirstOrDefaultAsync ( IQueryable < TResource > entities )
327
327
{
328
- return ( entities is IAsyncEnumerable < TEntity > )
328
+ return ( entities is IAsyncEnumerable < TResource > )
329
329
? await entities . FirstOrDefaultAsync ( )
330
330
: entities . FirstOrDefault ( ) ;
331
331
}
332
332
333
333
/// <inheritdoc />
334
- public async Task < IReadOnlyList < TEntity > > ToListAsync ( IQueryable < TEntity > entities )
334
+ public async Task < IReadOnlyList < TResource > > ToListAsync ( IQueryable < TResource > entities )
335
335
{
336
- return ( entities is IAsyncEnumerable < TEntity > )
336
+ return ( entities is IAsyncEnumerable < TResource > )
337
337
? await entities . ToListAsync ( )
338
338
: entities . ToList ( ) ;
339
339
}
@@ -351,7 +351,7 @@ public async Task<IReadOnlyList<TEntity>> ToListAsync(IQueryable<TEntity> entiti
351
351
/// after which the reassignment `p1.todoItems = [t3, t4]` will actually
352
352
/// make EF Core perform a complete replace. This method does the loading of `[t1, t2]`.
353
353
/// </summary>
354
- protected void LoadCurrentRelationships ( TEntity oldEntity , RelationshipAttribute relationshipAttribute )
354
+ protected void LoadCurrentRelationships ( TResource oldEntity , RelationshipAttribute relationshipAttribute )
355
355
{
356
356
if ( relationshipAttribute is HasManyThroughAttribute throughAttribute )
357
357
{
@@ -369,7 +369,7 @@ protected void LoadCurrentRelationships(TEntity oldEntity, RelationshipAttribute
369
369
/// use the join table (ArticleTags). This methods assigns the relationship value to entity
370
370
/// by taking care of that
371
371
/// </summary>
372
- private void AssignHasManyThrough ( TEntity entity , HasManyThroughAttribute hasManyThrough , IList relationshipValue )
372
+ private void AssignHasManyThrough ( TResource entity , HasManyThroughAttribute hasManyThrough , IList relationshipValue )
373
373
{
374
374
var pointers = relationshipValue . Cast < IIdentifiable > ( ) ;
375
375
var throughRelationshipCollection = Activator . CreateInstance ( hasManyThrough . ThroughProperty . PropertyType ) as IList ;
@@ -414,8 +414,8 @@ private IIdentifiable AttachOrGetTracked(IIdentifiable relationshipValue)
414
414
}
415
415
416
416
/// <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 >
419
419
{
420
420
public DefaultResourceRepository ( ITargetedFields targetedFields ,
421
421
IDbContextResolver contextResolver ,
0 commit comments