protected static void InitilizeGlobalFilters <T>(Expression <Func <T, bool> > filterExpression) where T : class { QueryFilterManager.Filter <T>(p => p.Where(filterExpression)); isAnyFilterInitilized = true; }
public static void ConfigFilters() { QueryFilterManager.AllowPropertyFilter = false; QueryFilterManager.Filter <AppUser>(FilterKeys.ActiveUsers, x => x.Where(t => !t.IsSoftDeleted)); QueryFilterManager.Filter <UserWallet>(FilterKeys.ActiveWallet, x => x.Where(t => !t.IsSoftDeleted)); QueryFilterManager.Filter <BusRoute>(FilterKeys.ActiveRoutes, x => x.Where(t => !t.IsSoftDeleted)); QueryFilterManager.Filter <Bus>(FilterKeys.ActiveBuses, x => x.Where(t => !t.IsSoftDeleted)); QueryFilterManager.Filter <AppUser>(FilterKeys.RegisteredUsers, x => x.Where(t => t.EmailConfirmed && !t.LockedOut), false); }
public DBContext() : base("name=DBContext") { QueryFilterManager.Filter <Kitaplar>(c => c.Where(x => x.isActive == true)); QueryFilterManager.Filter <KullanimDetay>(c => c.Where(x => x.isActive == true)); QueryFilterManager.Filter <Raflar>(c => c.Where(x => x.isActive == true)); QueryFilterManager.Filter <Yorumlar>(c => c.Where(x => x.isActive == true)); QueryFilterManager.InitilizeGlobalFilter(this); }
private void NoFilter() { QueryFilterManager.Filter <Product>(q => q.Where(p => p.IsActive)); using (var db = new DataContext()) { var count = db.Products.AsNoFilter().Count(); Console.WriteLine($"Products count: {count}"); } }
public ApplicationDbContext(AppTenant tenant) { if (tenant != null) { this.tenant = tenant; this.Seed(this.tenant); var tenantId = this.tenant.AppTenantId; QueryFilterManager.Filter <Page>(q => q.Where(x => x.AppTenantId == tenantId)); QueryFilterManager.InitilizeGlobalFilter(this); } }
protected override void OnModelCreating(DbModelBuilder modelBuilder) { DbInterception.Add(new NLogCommandInterceptor(Log.App)); // TODO: IoC Configurable QueryFilterManager.Filter <ISoftDeletable>(q => q.Where(x => x.IsDeleted == false)); // TODO: Move mappings modelBuilder.Entity <Product>().HasMany(x => x.Stocks); modelBuilder.Entity <Stock>().HasKey(x => new { x.Id, x.ProductId }); modelBuilder.Properties() .Where(p => p.Name.EndsWith("Buddy")) .Configure(p => p.HasColumnName(p.ClrPropertyInfo.Name.Replace("Buddy", string.Empty))); }
private static void RunQueriesWithGlobalFilter() { Console.WriteLine("\n ** Test 2: Queries with global filter"); QueryFilterManager.Filter <Contact>(q => q.Where(x => x.IsDeleted == true)); using (var dbContext = new TestDbContext()) { Console.WriteLine("\t First time query execution"); QueryFilterManager.InitilizeGlobalFilter(dbContext); dbContext.Contacts.ToList(); } using (var dbContext = new TestDbContext()) { Console.WriteLine("\t Second time query execution"); QueryFilterManager.InitilizeGlobalFilter(dbContext); dbContext.Contacts.ToList(); } }
private void GlobalFilter() { QueryFilterManager.Filter <Product>(q => q.Where(p => p.IsActive)); using (var db = new DataContext()) { var count = db.Products.Count(); Console.WriteLine($"Products count: {count}"); } using (var db = new DataContext()) { var category = db.Categories.FirstOrDefault(); var count = category.Products.Count; Console.WriteLine($"Products count in category {category.Name}: {count}"); } }
public static void Run_Filter() { // CREATE global filter QueryFilterManager.Filter <Flight>(x => x.Where(c => c.Departure == "Rome")); var ctx = new DA.WWWingsContext(); ctx.Log(); // TIP: Add this line in EntitiesContext constructor instead QueryFilterManager.InitilizeGlobalFilter(ctx); // SELECT * FROM Customer WHERE IsActive = true var customer = ctx.FlightSet.ToList(); foreach (var f in customer) { Console.WriteLine(f); } }
public static void CreateGlobalManagerFilter(bool isEnabled, string fixResharper = null, bool?enableFilter1 = null, bool?enableFilter2 = null, bool?enableFilter3 = null, bool?enableFilter4 = null, bool?excludeClass = null, bool?excludeInterface = null, bool?excludeBaseClass = null, bool?excludeBaseInterface = null, bool?includeClass = null, bool?includeInterface = null, bool?includeBaseClass = null, bool?includeBaseInterface = null) { if (enableFilter1 != null) { QueryFilterManager.Filter <Inheritance_Interface_Entity>(Filter.Filter1, entities => entities.Where(x => x.ColumnInt != 1), isEnabled); if (!isEnabled && enableFilter1.Value) { QueryFilterManager.Filter(Filter.Filter1).IsDefaultEnabled = true; } else if (isEnabled && !enableFilter1.Value) { QueryFilterManager.Filter(Filter.Filter1).IsDefaultEnabled = false; } } if (enableFilter2 != null) { QueryFilterManager.Filter <Inheritance_Interface_IEntity>(Filter.Filter2, entities => entities.Where(x => x.ColumnInt != 2), isEnabled); if (!isEnabled && enableFilter2.Value) { QueryFilterManager.Filter(Filter.Filter2).IsDefaultEnabled = true; } else if (isEnabled && !enableFilter2.Value) { QueryFilterManager.Filter(Filter.Filter2).IsDefaultEnabled = false; } } if (enableFilter3 != null) { QueryFilterManager.Filter <Inheritance_Interface_Base>(Filter.Filter3, entities => entities.Where(x => x.ColumnInt != 3), isEnabled); if (!isEnabled && enableFilter3.Value) { QueryFilterManager.Filter(Filter.Filter3).IsDefaultEnabled = true; } else if (isEnabled && !enableFilter3.Value) { QueryFilterManager.Filter(Filter.Filter3).IsDefaultEnabled = false; } } if (enableFilter4 != null) { QueryFilterManager.Filter <Inheritance_Interface_IBase>(Filter.Filter4, entities => entities.Where(x => x.ColumnInt != 4), isEnabled); if (!isEnabled && enableFilter4.Value) { QueryFilterManager.Filter(Filter.Filter4).IsDefaultEnabled = true; } else if (isEnabled && !enableFilter4.Value) { QueryFilterManager.Filter(Filter.Filter4).IsDefaultEnabled = false; } } if (excludeClass != null && excludeClass.Value) { QueryFilterManager.Filter(Filter.Filter1).Disable(typeof(Inheritance_Interface_Entity)); } if (excludeInterface != null && excludeInterface.Value) { QueryFilterManager.Filter(Filter.Filter2).Disable(typeof(Inheritance_Interface_IEntity)); } if (excludeBaseClass != null && excludeBaseClass.Value) { QueryFilterManager.Filter(Filter.Filter3).Disable(typeof(Inheritance_Interface_Base)); } if (excludeBaseInterface != null && excludeBaseInterface.Value) { QueryFilterManager.Filter(Filter.Filter4).Disable(typeof(Inheritance_Interface_IBase)); } if (includeClass != null && includeClass.Value) { QueryFilterManager.Filter(Filter.Filter1).Enable(typeof(Inheritance_Interface_IEntity)); } if (includeInterface != null && includeInterface.Value) { QueryFilterManager.Filter(Filter.Filter2).Enable(typeof(Inheritance_Interface_IEntity)); } if (includeBaseClass != null && includeBaseClass.Value) { QueryFilterManager.Filter(Filter.Filter3).Enable(typeof(Inheritance_Interface_Base)); } if (includeBaseInterface != null && includeBaseInterface.Value) { QueryFilterManager.Filter(Filter.Filter4).Enable(typeof(Inheritance_Interface_IBase)); } }
public static void CreateGlobalManagerFilter(bool isEnabled, string fixResharper = null, bool?enableFilter1 = null, bool?enableFilter2 = null, bool?enableFilter3 = null, bool?enableFilter4 = null, bool?excludeClass = null, bool?excludeInterface = null, bool?excludeBaseClass = null, bool?excludeBaseInterface = null, bool?includeClass = null, bool?includeInterface = null, bool?includeBaseClass = null, bool?includeBaseInterface = null) { #if EFCORE // TODO: Remove this when cast issue will be fixed QueryFilterManager.GlobalFilters.Clear(); QueryFilterManager.GlobalInitializeFilterActions.Clear(); #endif if (enableFilter1 != null) { QueryFilterManager.Filter <Inheritance_Interface_Entity>(Filter.Filter1, entities => entities.Where(x => x.ColumnInt != 1), isEnabled); if (!isEnabled && enableFilter1.Value) { QueryFilterManager.Filter(Filter.Filter1).IsDefaultEnabled = true; } else if (isEnabled && !enableFilter1.Value) { QueryFilterManager.Filter(Filter.Filter1).IsDefaultEnabled = false; } } if (enableFilter2 != null) { QueryFilterManager.Filter <Inheritance_Interface_IEntity>(Filter.Filter2, entities => entities.Where(x => x.ColumnInt != 2), isEnabled); if (!isEnabled && enableFilter2.Value) { QueryFilterManager.Filter(Filter.Filter2).IsDefaultEnabled = true; } else if (isEnabled && !enableFilter2.Value) { QueryFilterManager.Filter(Filter.Filter2).IsDefaultEnabled = false; } } if (enableFilter3 != null) { QueryFilterManager.Filter <Inheritance_Interface_Base>(Filter.Filter3, entities => entities.Where(x => x.ColumnInt != 3), isEnabled); if (!isEnabled && enableFilter3.Value) { QueryFilterManager.Filter(Filter.Filter3).IsDefaultEnabled = true; } else if (isEnabled && !enableFilter3.Value) { QueryFilterManager.Filter(Filter.Filter3).IsDefaultEnabled = false; } } if (enableFilter4 != null) { QueryFilterManager.Filter <Inheritance_Interface_IBase>(Filter.Filter4, entities => entities.Where(x => x.ColumnInt != 4), isEnabled); if (!isEnabled && enableFilter4.Value) { QueryFilterManager.Filter(Filter.Filter4).IsDefaultEnabled = true; } else if (isEnabled && !enableFilter4.Value) { QueryFilterManager.Filter(Filter.Filter4).IsDefaultEnabled = false; } } if (excludeClass != null && excludeClass.Value) { QueryFilterManager.Filter(Filter.Filter1).Disable(typeof(Inheritance_Interface_Entity)); } if (excludeInterface != null && excludeInterface.Value) { QueryFilterManager.Filter(Filter.Filter2).Disable(typeof(Inheritance_Interface_IEntity)); } if (excludeBaseClass != null && excludeBaseClass.Value) { QueryFilterManager.Filter(Filter.Filter3).Disable(typeof(Inheritance_Interface_Base)); } if (excludeBaseInterface != null && excludeBaseInterface.Value) { QueryFilterManager.Filter(Filter.Filter4).Disable(typeof(Inheritance_Interface_IBase)); } if (includeClass != null && includeClass.Value) { QueryFilterManager.Filter(Filter.Filter1).Enable(typeof(Inheritance_Interface_IEntity)); } if (includeInterface != null && includeInterface.Value) { QueryFilterManager.Filter(Filter.Filter2).Enable(typeof(Inheritance_Interface_IEntity)); } if (includeBaseClass != null && includeBaseClass.Value) { QueryFilterManager.Filter(Filter.Filter3).Enable(typeof(Inheritance_Interface_Base)); } if (includeBaseInterface != null && includeBaseInterface.Value) { QueryFilterManager.Filter(Filter.Filter4).Enable(typeof(Inheritance_Interface_IBase)); } }
public static IServiceCollection AddInactivable(this IServiceCollection services) { QueryFilterManager.Filter <IInactivable>(q => q.Where(x => x.IsInactive == false)); return(services); }
public RPCSContext(DbContextOptions <RPCSContext> options) : base(options) { QueryFilterManager.Filter <BaseModel>("IsVersion", m => m.Where(x => !x.IsVersion), true); QueryFilterManager.Filter <BaseModel>("IsDeleted", m => m.Where(x => !x.IsDeleted), true); QueryFilterManager.InitilizeGlobalFilter(this); }