@@ -47,7 +47,8 @@ public virtual IEnumerable<TEntity> BeforeUpdate<TEntity>(IEnumerable<TEntity> e
47
47
{
48
48
if ( GetHook ( ResourceHook . BeforeUpdate , entities , out var container , out var node ) )
49
49
{
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 ) ;
51
52
var diff = new ResourceDiff < TEntity > ( node . UniqueEntities , dbValues , node . PrincipalsToNextLayer ( ) ) ;
52
53
IEnumerable < TEntity > updated = container . BeforeUpdate ( diff , pipeline ) ;
53
54
node . UpdateUnique ( updated ) ;
@@ -79,7 +80,8 @@ public virtual IEnumerable<TEntity> BeforeDelete<TEntity>(IEnumerable<TEntity> e
79
80
{
80
81
if ( GetHook ( ResourceHook . BeforeDelete , entities , out var container , out var node ) )
81
82
{
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 ;
83
85
var affected = new AffectedResources < TEntity > ( targetEntities , node . PrincipalsToNextLayer ( ) ) ;
84
86
85
87
IEnumerable < TEntity > updated = container . BeforeDelete ( affected , pipeline ) ;
@@ -251,7 +253,8 @@ void FireNestedBeforeUpdateHooks(ResourcePipeline pipeline, EntityChildLayer lay
251
253
{
252
254
if ( uniqueEntities . Cast < IIdentifiable > ( ) . Any ( ) )
253
255
{
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 ) ;
255
258
var resourcesByRelationship = CreateRelationshipHelper ( entityType , node . RelationshipsFromPreviousLayer . GetDependentEntities ( ) , dbValues ) ;
256
259
var allowedIds = CallHook ( nestedHookcontainer , ResourceHook . BeforeUpdateRelationship , new object [ ] { GetIds ( uniqueEntities ) , resourcesByRelationship , pipeline } ) . Cast < string > ( ) ;
257
260
var updated = GetAllowedEntities ( uniqueEntities , allowedIds ) ;
@@ -281,7 +284,7 @@ void FireNestedBeforeUpdateHooks(ResourcePipeline pipeline, EntityChildLayer lay
281
284
/// Given a source of entities, gets the implicitly affected entities
282
285
/// from the database and calls the BeforeImplicitUpdateRelationship hook.
283
286
/// </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 )
285
288
{
286
289
var container = _executorHelper . GetResourceHookContainer ( entityTypeToInclude , ResourceHook . BeforeImplicitUpdateRelationship ) ;
287
290
if ( container == null ) return ;
@@ -310,10 +313,10 @@ void ValidateHookResponse<T>(IEnumerable<T> returnedList, ResourcePipeline pipel
310
313
/// NOTE: in JADNC usage, the root layer is ALWAYS homogenous, so we can be sure that for every
311
314
/// relationship to the previous layer, the principal type is the same.
312
315
/// </summary>
313
- ( Dictionary < RelationshipProxy , IEnumerable > , PrincipalType ) GetDependentImplicitsTargets ( Dictionary < RelationshipProxy , IEnumerable > dependentEntities )
316
+ ( Dictionary < RelationshipAttribute , IEnumerable > , PrincipalType ) GetDependentImplicitsTargets ( Dictionary < RelationshipAttribute , IEnumerable > dependentEntities )
314
317
{
315
318
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 ) ;
317
320
return ( byInverseRelationship , principalType ) ;
318
321
319
322
}
@@ -350,17 +353,17 @@ object ThrowJsonApiExceptionOnError(Func<object> action)
350
353
/// If <paramref name="dbValues"/> are included, the values of the entries in <paramref name="prevLayerRelationships"/> need to be replaced with these values.
351
354
/// </summary>
352
355
/// <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 )
354
357
{
355
358
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 ) ;
357
360
}
358
361
359
362
/// <summary>
360
363
/// Replaces the entities in the values of the prevLayerRelationships dictionary
361
364
/// with the corresponding entities loaded from the db.
362
365
/// </summary>
363
- void ReplaceWithDbValues ( Dictionary < RelationshipProxy , IEnumerable > prevLayerRelationships , IEnumerable < IIdentifiable > dbValues )
366
+ void ReplaceWithDbValues ( Dictionary < RelationshipAttribute , IEnumerable > prevLayerRelationships , IEnumerable < IIdentifiable > dbValues )
364
367
{
365
368
foreach ( var key in prevLayerRelationships . Keys . ToList ( ) )
366
369
{
@@ -379,14 +382,14 @@ HashSet<IIdentifiable> GetAllowedEntities(IEnumerable source, IEnumerable<string
379
382
}
380
383
381
384
/// <summary>
382
- /// Gets the inverse <see cref="RelationshipProxy "/> for <paramref name="proxy "/>
385
+ /// Gets the inverse <see cref="RelationshipAttribute "/> for <paramref name="attribute "/>
383
386
/// </summary>
384
- RelationshipProxy GetInverseRelationship ( RelationshipProxy proxy )
387
+ RelationshipAttribute GetInverseRelationship ( RelationshipAttribute attribute )
385
388
{
386
- return new RelationshipProxy ( _graph . GetInverseRelationship ( proxy . Attribute ) , proxy . PrincipalType , false ) ;
389
+ return _graph . GetInverseRelationship ( attribute ) ;
387
390
}
388
391
389
- IEnumerable LoadDbValues ( Type containerEntityType , IEnumerable uniqueEntities , ResourceHook targetHook , RelationshipProxy [ ] relationshipsToNextLayer )
392
+ IEnumerable LoadDbValues ( Type containerEntityType , IEnumerable uniqueEntities , ResourceHook targetHook , RelationshipAttribute [ ] relationshipsToNextLayer )
390
393
{
391
394
if ( ! _executorHelper . ShouldLoadDbValues ( containerEntityType , targetHook ) ) return null ;
392
395
return _executorHelper . LoadDbValues ( containerEntityType , uniqueEntities , targetHook , relationshipsToNextLayer ) ;
0 commit comments