@@ -47,9 +47,14 @@ public DefaultResourceRepository(
47
47
}
48
48
49
49
/// <inheritdoc />
50
- public virtual IQueryable < TResource > Get ( ) => _dbSet ;
50
+ public virtual IQueryable < TResource > Get ( )
51
+ {
52
+ var resourceContext = _resourceGraph . GetResourceContext < TResource > ( ) ;
53
+ return EagerLoad ( _dbSet , resourceContext . EagerLoads ) ;
54
+ }
55
+
51
56
/// <inheritdoc />
52
- public virtual IQueryable < TResource > Get ( TId id ) => _dbSet . Where ( e => e . Id . Equals ( id ) ) ;
57
+ public virtual IQueryable < TResource > Get ( TId id ) => Get ( ) . Where ( e => e . Id . Equals ( id ) ) ;
53
58
54
59
/// <inheritdoc />
55
60
public virtual IQueryable < TResource > Select ( IQueryable < TResource > entities , IEnumerable < AttrAttribute > fields = null )
@@ -279,6 +284,19 @@ public virtual async Task<bool> DeleteAsync(TId id)
279
284
return true ;
280
285
}
281
286
287
+ private IQueryable < TResource > EagerLoad ( IQueryable < TResource > entities , IEnumerable < EagerLoadAttribute > attributes , string chainPrefix = null )
288
+ {
289
+ foreach ( var attribute in attributes )
290
+ {
291
+ string path = chainPrefix != null ? chainPrefix + "." + attribute . Property . Name : attribute . Property . Name ;
292
+ entities = entities . Include ( path ) ;
293
+
294
+ entities = EagerLoad ( entities , attribute . Children , path ) ;
295
+ }
296
+
297
+ return entities ;
298
+ }
299
+
282
300
public virtual IQueryable < TResource > Include ( IQueryable < TResource > entities , IEnumerable < RelationshipAttribute > inclusionChain = null )
283
301
{
284
302
if ( inclusionChain == null || ! inclusionChain . Any ( ) )
@@ -288,10 +306,15 @@ public virtual IQueryable<TResource> Include(IQueryable<TResource> entities, IEn
288
306
289
307
string internalRelationshipPath = null ;
290
308
foreach ( var relationship in inclusionChain )
291
- internalRelationshipPath = ( internalRelationshipPath == null )
309
+ {
310
+ internalRelationshipPath = internalRelationshipPath == null
292
311
? relationship . RelationshipPath
293
312
: $ "{ internalRelationshipPath } .{ relationship . RelationshipPath } ";
294
313
314
+ var resourceContext = _resourceGraph . GetResourceContext ( relationship . RightType ) ;
315
+ entities = EagerLoad ( entities , resourceContext . EagerLoads , internalRelationshipPath ) ;
316
+ }
317
+
295
318
return entities . Include ( internalRelationshipPath ) ;
296
319
}
297
320
0 commit comments