11
2+ using System ;
23using System . Collections ;
34using System . Collections . Generic ;
5+ using System . Linq ;
6+ using JsonApiDotNetCore . Internal ;
47using JsonApiDotNetCore . Models ;
58
69namespace JsonApiDotNetCore . Hooks
710{
11+
812 /// <summary>
913 /// A helper class that provides insight in what is to be updated. The
1014 /// <see cref="IEntityDiff{TEntity}.RequestEntities"/> property reflects what was parsed from the incoming request,
@@ -21,14 +25,21 @@ public interface IEntityDiff<TEntity> : IAffectedRelationships<TEntity> where TE
2125
2226 public class EntityDiff < TEntity > : AffectedRelationships < TEntity > , IEntityDiff < TEntity > where TEntity : class , IIdentifiable
2327 {
28+ private readonly HashSet < TEntity > _databaseEntities ;
29+ public HashSet < TEntity > DatabaseEntities { get => _databaseEntities ?? ThrowNoDbValuesError ( ) ; }
30+
2431 public HashSet < TEntity > RequestEntities { get ; private set ; }
25- public HashSet < TEntity > DatabaseEntities { get ; private set ; }
2632 public EntityDiff ( IEnumerable requestEntities ,
2733 IEnumerable databaseEntities ,
28- Dictionary < RelationshipProxy , IEnumerable > relationships ) : base ( relationships )
34+ Dictionary < RelationshipProxy , IEnumerable > relationships ) : base ( relationships )
2935 {
3036 RequestEntities = ( HashSet < TEntity > ) requestEntities ;
31- DatabaseEntities = ( HashSet < TEntity > ) databaseEntities ;
37+ _databaseEntities = ( HashSet < TEntity > ) databaseEntities ;
38+ }
39+
40+ private HashSet < TEntity > ThrowNoDbValuesError ( )
41+ {
42+ throw new MemberAccessException ( "Cannot access database entities if the LoadDatabaseValues option is set to false" ) ;
3243 }
3344 }
3445}
0 commit comments