@@ -42,23 +42,30 @@ public DefaultResourceRepository(
42
42
_context = contextResolver . GetContext ( ) ;
43
43
_dbSet = _context . Set < TResource > ( ) ;
44
44
_logger = loggerFactory . CreateLogger < DefaultResourceRepository < TResource , TId > > ( ) ;
45
-
46
- _logger . LogTrace ( "Executing constructor." ) ;
47
45
}
48
46
49
47
/// <inheritdoc />
50
48
public virtual IQueryable < TResource > Get ( )
51
49
{
50
+ _logger . LogTrace ( $ "Entering { nameof ( Get ) } ().") ;
51
+
52
52
var resourceContext = _resourceGraph . GetResourceContext < TResource > ( ) ;
53
53
return EagerLoad ( _dbSet , resourceContext . EagerLoads ) ;
54
54
}
55
55
56
56
/// <inheritdoc />
57
- public virtual IQueryable < TResource > Get ( TId id ) => Get ( ) . Where ( e => e . Id . Equals ( id ) ) ;
57
+ public virtual IQueryable < TResource > Get ( TId id )
58
+ {
59
+ _logger . LogTrace ( $ "Entering { nameof ( Get ) } ('{ id } ').") ;
60
+
61
+ return Get ( ) . Where ( e => e . Id . Equals ( id ) ) ;
62
+ }
58
63
59
64
/// <inheritdoc />
60
65
public virtual IQueryable < TResource > Select ( IQueryable < TResource > entities , IEnumerable < AttrAttribute > fields = null )
61
66
{
67
+ _logger . LogTrace ( $ "Entering { nameof ( Select ) } ({ nameof ( entities ) } , { nameof ( fields ) } ).") ;
68
+
62
69
if ( fields != null && fields . Any ( ) )
63
70
return entities . Select ( fields ) ;
64
71
@@ -68,6 +75,8 @@ public virtual IQueryable<TResource> Select(IQueryable<TResource> entities, IEnu
68
75
/// <inheritdoc />
69
76
public virtual IQueryable < TResource > Filter ( IQueryable < TResource > entities , FilterQueryContext filterQueryContext )
70
77
{
78
+ _logger . LogTrace ( $ "Entering { nameof ( Filter ) } ({ nameof ( entities ) } , { nameof ( filterQueryContext ) } ).") ;
79
+
71
80
if ( filterQueryContext . IsCustom )
72
81
{
73
82
var query = ( Func < IQueryable < TResource > , FilterQuery , IQueryable < TResource > > ) filterQueryContext . CustomQuery ;
@@ -79,12 +88,16 @@ public virtual IQueryable<TResource> Filter(IQueryable<TResource> entities, Filt
79
88
/// <inheritdoc />
80
89
public virtual IQueryable < TResource > Sort ( IQueryable < TResource > entities , SortQueryContext sortQueryContext )
81
90
{
91
+ _logger . LogTrace ( $ "Entering { nameof ( Sort ) } ({ nameof ( entities ) } , { nameof ( sortQueryContext ) } ).") ;
92
+
82
93
return entities . Sort ( sortQueryContext ) ;
83
94
}
84
95
85
96
/// <inheritdoc />
86
97
public virtual async Task < TResource > CreateAsync ( TResource entity )
87
98
{
99
+ _logger . LogTrace ( $ "Entering { nameof ( CreateAsync ) } ({ ( entity == null ? "null" : "object" ) } ).") ;
100
+
88
101
foreach ( var relationshipAttr in _targetedFields . Relationships )
89
102
{
90
103
object trackedRelationshipValue = GetTrackedRelationshipValue ( relationshipAttr , entity , out bool relationshipWasAlreadyTracked ) ;
@@ -184,6 +197,8 @@ private void DetachRelationships(TResource entity)
184
197
/// <inheritdoc />
185
198
public virtual async Task < TResource > UpdateAsync ( TResource updatedEntity )
186
199
{
200
+ _logger . LogTrace ( $ "Entering { nameof ( UpdateAsync ) } ({ ( updatedEntity == null ? "null" : "object" ) } ).") ;
201
+
187
202
var databaseEntity = await Get ( updatedEntity . Id ) . FirstOrDefaultAsync ( ) ;
188
203
if ( databaseEntity == null )
189
204
return null ;
@@ -264,6 +279,8 @@ private IIdentifiable GetTrackedHasOneRelationshipValue(IIdentifiable relationsh
264
279
/// <inheritdoc />
265
280
public async Task UpdateRelationshipsAsync ( object parent , RelationshipAttribute relationship , IEnumerable < string > relationshipIds )
266
281
{
282
+ _logger . LogTrace ( $ "Entering { nameof ( UpdateRelationshipsAsync ) } ({ nameof ( parent ) } , { nameof ( relationship ) } , { nameof ( relationshipIds ) } ).") ;
283
+
267
284
var typeToUpdate = ( relationship is HasManyThroughAttribute hasManyThrough )
268
285
? hasManyThrough . ThroughType
269
286
: relationship . RightType ;
@@ -277,6 +294,8 @@ public async Task UpdateRelationshipsAsync(object parent, RelationshipAttribute
277
294
/// <inheritdoc />
278
295
public virtual async Task < bool > DeleteAsync ( TId id )
279
296
{
297
+ _logger . LogTrace ( $ "Entering { nameof ( DeleteAsync ) } ('{ id } ').") ;
298
+
280
299
var entity = await Get ( id ) . FirstOrDefaultAsync ( ) ;
281
300
if ( entity == null ) return false ;
282
301
_dbSet . Remove ( entity ) ;
@@ -299,6 +318,8 @@ private IQueryable<TResource> EagerLoad(IQueryable<TResource> entities, IEnumera
299
318
300
319
public virtual IQueryable < TResource > Include ( IQueryable < TResource > entities , IEnumerable < RelationshipAttribute > inclusionChain = null )
301
320
{
321
+ _logger . LogTrace ( $ "Entering { nameof ( Include ) } ({ nameof ( entities ) } , { nameof ( inclusionChain ) } ).") ;
322
+
302
323
if ( inclusionChain == null || ! inclusionChain . Any ( ) )
303
324
{
304
325
return entities ;
@@ -321,6 +342,8 @@ public virtual IQueryable<TResource> Include(IQueryable<TResource> entities, IEn
321
342
/// <inheritdoc />
322
343
public virtual async Task < IEnumerable < TResource > > PageAsync ( IQueryable < TResource > entities , int pageSize , int pageNumber )
323
344
{
345
+ _logger . LogTrace ( $ "Entering { nameof ( PageAsync ) } ({ nameof ( entities ) } , { pageSize } , { pageNumber } ).") ;
346
+
324
347
// the IQueryable returned from the hook executor is sometimes consumed here.
325
348
// In this case, it does not support .ToListAsync(), so we use the method below.
326
349
if ( pageNumber >= 0 )
@@ -351,6 +374,8 @@ public virtual async Task<IEnumerable<TResource>> PageAsync(IQueryable<TResource
351
374
/// <inheritdoc />
352
375
public async Task < int > CountAsync ( IQueryable < TResource > entities )
353
376
{
377
+ _logger . LogTrace ( $ "Entering { nameof ( CountAsync ) } ({ nameof ( entities ) } ).") ;
378
+
354
379
if ( entities is IAsyncEnumerable < TResource > )
355
380
{
356
381
return await entities . CountAsync ( ) ;
@@ -361,6 +386,8 @@ public async Task<int> CountAsync(IQueryable<TResource> entities)
361
386
/// <inheritdoc />
362
387
public virtual async Task < TResource > FirstOrDefaultAsync ( IQueryable < TResource > entities )
363
388
{
389
+ _logger . LogTrace ( $ "Entering { nameof ( FirstOrDefaultAsync ) } ({ nameof ( entities ) } ).") ;
390
+
364
391
return ( entities is IAsyncEnumerable < TResource > )
365
392
? await entities . FirstOrDefaultAsync ( )
366
393
: entities . FirstOrDefault ( ) ;
@@ -369,6 +396,8 @@ public virtual async Task<TResource> FirstOrDefaultAsync(IQueryable<TResource> e
369
396
/// <inheritdoc />
370
397
public async Task < IReadOnlyList < TResource > > ToListAsync ( IQueryable < TResource > entities )
371
398
{
399
+ _logger . LogTrace ( $ "Entering { nameof ( ToListAsync ) } ({ nameof ( entities ) } ).") ;
400
+
372
401
if ( entities is IAsyncEnumerable < TResource > )
373
402
{
374
403
return await entities . ToListAsync ( ) ;
0 commit comments