/// <summary> /// This returns a where filter that returns all the valid entities that have been cascade soft deleted /// </summary> /// <typeparam name="TEntity"></typeparam> /// <typeparam name="TInterface"></typeparam> /// <param name="config"></param> /// <param name="levelToLookFor"></param> /// <returns></returns> public static Expression <Func <TEntity, bool> > FilterToGetValueCascadeSoftDeletedEntities <TEntity, TInterface>( this SoftDeleteConfiguration <TInterface, byte> config, byte levelToLookFor) where TInterface : class where TEntity : TInterface { return(FilterToGetSoftDeletedEntities <TEntity, TInterface, byte>(config.GetSoftDeleteValue, config.OtherFilters, levelToLookFor)); }
public GenericSingletonLoader(DbContext context, SoftDeleteConfiguration <TInterface, byte> config, object principalInstance, PropertyInfo propertyInfo, byte levelToLookFor) { var query = context.Entry(principalInstance).Reference(propertyInfo.Name).Query(); FilteredSingleton = query.Provider.CreateQuery <TEntity>(query.Expression).IgnoreQueryFilters() .Where(config.FilterToGetValueCascadeSoftDeletedEntities <TEntity, TInterface>(levelToLookFor)).SingleOrDefault(); }
public CascadeWalker(DbContext context, SoftDeleteConfiguration <TInterface, byte> config, CascadeSoftDelWhatDoing whatDoing, bool readEveryTime) { _context = context; _config = config; _whatDoing = whatDoing; _readEveryTime = readEveryTime; }
/// <summary> /// This returns a where filter that returns all the valid entities that have been single soft deleted /// </summary> /// <typeparam name="TEntity"></typeparam> /// <typeparam name="TInterface"></typeparam> /// <param name="config"></param> /// <returns></returns> public static Expression <Func <TEntity, bool> > FilterToGetValueSingleSoftDeletedEntities <TEntity, TInterface>( this SoftDeleteConfiguration <TInterface, bool> config) where TInterface : class where TEntity : TInterface { if (config == null) { throw new ArgumentNullException(nameof(config)); } return(FilterToGetSoftDeletedEntities <TEntity, TInterface, bool>(config.GetSoftDeleteValue, config.OtherFilters, true)); }
/// <summary> /// This provides a equivalent to a SQL cascade delete, but using a soft delete approach. /// </summary> /// <param name="context"></param> /// <param name="config"></param> public CascadeSoftDelService(DbContext context, SoftDeleteConfiguration <TInterface, byte> config) { _context = context ?? throw new ArgumentNullException(nameof(context)); _config = config ?? throw new ArgumentNullException(nameof(config)); if (_config.GetSoftDeleteValue == null) { throw new InvalidOperationException($"You must set the {nameof(_config.GetSoftDeleteValue)} with a query to get the soft delete byte"); } if (_config.SetSoftDeleteValue == null) { throw new InvalidOperationException($"You must set the {nameof(_config.SetSoftDeleteValue)} with a function to set the value of the soft delete bool"); } }