/// <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 CascadeSoftDeleteConfiguration <TInterface> config, byte levelToLookFor) where TInterface : class where TEntity : TInterface { return(FilterToGetSoftDeletedEntities <TEntity, TInterface, byte>(config.GetSoftDeleteValue, config.OtherFilters, levelToLookFor)); }
public GenericSingletonLoader(DbContext context, CascadeSoftDeleteConfiguration <TInterface> config, bool isAsync, object principalInstance, PropertyInfo propertyInfo, byte levelToLookFor) { _isAsync = isAsync; var query = context.Entry(principalInstance).Reference(propertyInfo.Name).Query(); _queryOfFilteredSingle = query.Provider.CreateQuery <TEntity>(query.Expression).IgnoreQueryFilters() .Where(config.FilterToGetValueCascadeSoftDeletedEntities <TEntity, TInterface>(levelToLookFor)); }
public CascadeWalker(DbContext context, CascadeSoftDeleteConfiguration <TInterface> config, bool isAsync, CascadeSoftDelWhatDoing whatDoing, bool readEveryTime) { _context = context; _config = config; _isAsync = isAsync; _whatDoing = whatDoing; _readEveryTime = readEveryTime && whatDoing == CascadeSoftDelWhatDoing.SoftDelete; }
/// <summary> /// This provides a equivalent to a SQL cascade delete, but using a soft delete approach. /// </summary> /// <param name="config"></param> public CascadeSoftDelServiceAsync(CascadeSoftDeleteConfiguration <TInterface> config) { _config = config ?? throw new ArgumentNullException(nameof(config)); _context = config.Context ?? throw new ArgumentNullException(nameof(config), "You must provide the DbContext"); 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"); } }