@@ -47,9 +47,14 @@ public DefaultResourceRepository(
4747 }
4848
4949 /// <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+
5156 /// <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 ) ) ;
5358
5459 /// <inheritdoc />
5560 public virtual IQueryable < TResource > Select ( IQueryable < TResource > entities , IEnumerable < AttrAttribute > fields = null )
@@ -279,6 +284,19 @@ public virtual async Task<bool> DeleteAsync(TId id)
279284 return true ;
280285 }
281286
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+
282300 public virtual IQueryable < TResource > Include ( IQueryable < TResource > entities , IEnumerable < RelationshipAttribute > inclusionChain = null )
283301 {
284302 if ( inclusionChain == null || ! inclusionChain . Any ( ) )
@@ -288,10 +306,15 @@ public virtual IQueryable<TResource> Include(IQueryable<TResource> entities, IEn
288306
289307 string internalRelationshipPath = null ;
290308 foreach ( var relationship in inclusionChain )
291- internalRelationshipPath = ( internalRelationshipPath == null )
309+ {
310+ internalRelationshipPath = internalRelationshipPath == null
292311 ? relationship . RelationshipPath
293312 : $ "{ internalRelationshipPath } .{ relationship . RelationshipPath } ";
294313
314+ var resourceContext = _resourceGraph . GetResourceContext ( relationship . RightType ) ;
315+ entities = EagerLoad ( entities , resourceContext . EagerLoads , internalRelationshipPath ) ;
316+ }
317+
295318 return entities . Include ( internalRelationshipPath ) ;
296319 }
297320
0 commit comments