@@ -47,7 +47,8 @@ public virtual IEnumerable<TEntity> BeforeUpdate<TEntity>(IEnumerable<TEntity> e
4747 {
4848 if ( GetHook ( ResourceHook . BeforeUpdate , entities , out var container , out var node ) )
4949 {
50- var dbValues = LoadDbValues ( typeof ( TEntity ) , ( IEnumerable < TEntity > ) node . UniqueEntities , ResourceHook . BeforeUpdate , node . RelationshipsToNextLayer ) ;
50+ var relationships = node . RelationshipsToNextLayer . Select ( p => p . Attribute ) . ToArray ( ) ;
51+ var dbValues = LoadDbValues ( typeof ( TEntity ) , ( IEnumerable < TEntity > ) node . UniqueEntities , ResourceHook . BeforeUpdate , relationships ) ;
5152 var diff = new ResourceDiff < TEntity > ( node . UniqueEntities , dbValues , node . PrincipalsToNextLayer ( ) ) ;
5253 IEnumerable < TEntity > updated = container . BeforeUpdate ( diff , pipeline ) ;
5354 node . UpdateUnique ( updated ) ;
@@ -79,7 +80,8 @@ public virtual IEnumerable<TEntity> BeforeDelete<TEntity>(IEnumerable<TEntity> e
7980 {
8081 if ( GetHook ( ResourceHook . BeforeDelete , entities , out var container , out var node ) )
8182 {
82- var targetEntities = LoadDbValues ( typeof ( TEntity ) , ( IEnumerable < TEntity > ) node . UniqueEntities , ResourceHook . BeforeDelete , node . RelationshipsToNextLayer ) ?? node . UniqueEntities ;
83+ var relationships = node . RelationshipsToNextLayer . Select ( p => p . Attribute ) . ToArray ( ) ;
84+ var targetEntities = LoadDbValues ( typeof ( TEntity ) , ( IEnumerable < TEntity > ) node . UniqueEntities , ResourceHook . BeforeDelete , relationships ) ?? node . UniqueEntities ;
8385 var affected = new AffectedResources < TEntity > ( targetEntities , node . PrincipalsToNextLayer ( ) ) ;
8486
8587 IEnumerable < TEntity > updated = container . BeforeDelete ( affected , pipeline ) ;
@@ -251,7 +253,8 @@ void FireNestedBeforeUpdateHooks(ResourcePipeline pipeline, EntityChildLayer lay
251253 {
252254 if ( uniqueEntities . Cast < IIdentifiable > ( ) . Any ( ) )
253255 {
254- var dbValues = LoadDbValues ( entityType , uniqueEntities , ResourceHook . BeforeUpdateRelationship , node . RelationshipsToNextLayer ) ;
256+ var relationships = node . RelationshipsToNextLayer . Select ( p => p . Attribute ) . ToArray ( ) ;
257+ var dbValues = LoadDbValues ( entityType , uniqueEntities , ResourceHook . BeforeUpdateRelationship , relationships ) ;
255258 var resourcesByRelationship = CreateRelationshipHelper ( entityType , node . RelationshipsFromPreviousLayer . GetDependentEntities ( ) , dbValues ) ;
256259 var allowedIds = CallHook ( nestedHookcontainer , ResourceHook . BeforeUpdateRelationship , new object [ ] { GetIds ( uniqueEntities ) , resourcesByRelationship , pipeline } ) . Cast < string > ( ) ;
257260 var updated = GetAllowedEntities ( uniqueEntities , allowedIds ) ;
@@ -281,7 +284,7 @@ void FireNestedBeforeUpdateHooks(ResourcePipeline pipeline, EntityChildLayer lay
281284 /// Given a source of entities, gets the implicitly affected entities
282285 /// from the database and calls the BeforeImplicitUpdateRelationship hook.
283286 /// </summary>
284- void FireForAffectedImplicits ( Type entityTypeToInclude , Dictionary < RelationshipProxy , IEnumerable > implicitsTarget , ResourcePipeline pipeline , IEnumerable existingImplicitEntities = null )
287+ void FireForAffectedImplicits ( Type entityTypeToInclude , Dictionary < RelationshipAttribute , IEnumerable > implicitsTarget , ResourcePipeline pipeline , IEnumerable existingImplicitEntities = null )
285288 {
286289 var container = _executorHelper . GetResourceHookContainer ( entityTypeToInclude , ResourceHook . BeforeImplicitUpdateRelationship ) ;
287290 if ( container == null ) return ;
@@ -310,10 +313,10 @@ void ValidateHookResponse<T>(IEnumerable<T> returnedList, ResourcePipeline pipel
310313 /// NOTE: in JADNC usage, the root layer is ALWAYS homogenous, so we can be sure that for every
311314 /// relationship to the previous layer, the principal type is the same.
312315 /// </summary>
313- ( Dictionary < RelationshipProxy , IEnumerable > , PrincipalType ) GetDependentImplicitsTargets ( Dictionary < RelationshipProxy , IEnumerable > dependentEntities )
316+ ( Dictionary < RelationshipAttribute , IEnumerable > , PrincipalType ) GetDependentImplicitsTargets ( Dictionary < RelationshipAttribute , IEnumerable > dependentEntities )
314317 {
315318 PrincipalType principalType = dependentEntities . First ( ) . Key . PrincipalType ;
316- var byInverseRelationship = dependentEntities . Where ( kvp => kvp . Key . Attribute . InverseNavigation != null ) . ToDictionary ( kvp => GetInverseRelationship ( kvp . Key ) , kvp => kvp . Value ) ;
319+ var byInverseRelationship = dependentEntities . Where ( kvp => kvp . Key . InverseNavigation != null ) . ToDictionary ( kvp => GetInverseRelationship ( kvp . Key ) , kvp => kvp . Value ) ;
317320 return ( byInverseRelationship , principalType ) ;
318321
319322 }
@@ -350,17 +353,17 @@ object ThrowJsonApiExceptionOnError(Func<object> action)
350353 /// If <paramref name="dbValues"/> are included, the values of the entries in <paramref name="prevLayerRelationships"/> need to be replaced with these values.
351354 /// </summary>
352355 /// <returns>The relationship helper.</returns>
353- IAffectedRelationships CreateRelationshipHelper ( DependentType entityType , Dictionary < RelationshipProxy , IEnumerable > prevLayerRelationships , IEnumerable dbValues = null )
356+ IAffectedRelationships CreateRelationshipHelper ( DependentType entityType , Dictionary < RelationshipAttribute , IEnumerable > prevLayerRelationships , IEnumerable dbValues = null )
354357 {
355358 if ( dbValues != null ) ReplaceWithDbValues ( prevLayerRelationships , dbValues . Cast < IIdentifiable > ( ) ) ;
356- return ( IAffectedRelationships ) TypeHelper . CreateInstanceOfOpenType ( typeof ( AffectedRelationships < > ) , entityType , true , prevLayerRelationships ) ;
359+ return ( IAffectedRelationships ) TypeHelper . CreateInstanceOfOpenType ( typeof ( AffectedRelationships < > ) , entityType , prevLayerRelationships ) ;
357360 }
358361
359362 /// <summary>
360363 /// Replaces the entities in the values of the prevLayerRelationships dictionary
361364 /// with the corresponding entities loaded from the db.
362365 /// </summary>
363- void ReplaceWithDbValues ( Dictionary < RelationshipProxy , IEnumerable > prevLayerRelationships , IEnumerable < IIdentifiable > dbValues )
366+ void ReplaceWithDbValues ( Dictionary < RelationshipAttribute , IEnumerable > prevLayerRelationships , IEnumerable < IIdentifiable > dbValues )
364367 {
365368 foreach ( var key in prevLayerRelationships . Keys . ToList ( ) )
366369 {
@@ -379,14 +382,14 @@ HashSet<IIdentifiable> GetAllowedEntities(IEnumerable source, IEnumerable<string
379382 }
380383
381384 /// <summary>
382- /// Gets the inverse <see cref="RelationshipProxy "/> for <paramref name="proxy "/>
385+ /// Gets the inverse <see cref="RelationshipAttribute "/> for <paramref name="attribute "/>
383386 /// </summary>
384- RelationshipProxy GetInverseRelationship ( RelationshipProxy proxy )
387+ RelationshipAttribute GetInverseRelationship ( RelationshipAttribute attribute )
385388 {
386- return new RelationshipProxy ( _graph . GetInverseRelationship ( proxy . Attribute ) , proxy . PrincipalType , false ) ;
389+ return _graph . GetInverseRelationship ( attribute ) ;
387390 }
388391
389- IEnumerable LoadDbValues ( Type containerEntityType , IEnumerable uniqueEntities , ResourceHook targetHook , RelationshipProxy [ ] relationshipsToNextLayer )
392+ IEnumerable LoadDbValues ( Type containerEntityType , IEnumerable uniqueEntities , ResourceHook targetHook , RelationshipAttribute [ ] relationshipsToNextLayer )
390393 {
391394 if ( ! _executorHelper . ShouldLoadDbValues ( containerEntityType , targetHook ) ) return null ;
392395 return _executorHelper . LoadDbValues ( containerEntityType , uniqueEntities , targetHook , relationshipsToNextLayer ) ;
0 commit comments