From aeed317fcab085cdbfb8e10292233c7eee965271 Mon Sep 17 00:00:00 2001 From: Jonathan Magnan Date: Wed, 26 Jan 2022 09:02:00 -0500 Subject: [PATCH] Add ShouldIgnoreDynamicFilterInterceptor --- .../DynamicFilterInterceptor.cs | 6 +++--- .../DynamicFilterManager.cs | 15 +++++++++++++++ ...ntityFramework.DynamicFilters.Shared.projitems | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/EntityFramework.DynamicFilters.Shared/DynamicFilterManager.cs diff --git a/src/EntityFramework.DynamicFilters.Shared/DynamicFilterInterceptor.cs b/src/EntityFramework.DynamicFilters.Shared/DynamicFilterInterceptor.cs index dc7d1c1..7de4dba 100644 --- a/src/EntityFramework.DynamicFilters.Shared/DynamicFilterInterceptor.cs +++ b/src/EntityFramework.DynamicFilters.Shared/DynamicFilterInterceptor.cs @@ -11,15 +11,15 @@ public class DynamicFilterInterceptor : IDbCommandTreeInterceptor { public void TreeCreated(DbCommandTreeInterceptionContext interceptionContext) { + // https://github.com/zzzprojects/EntityFramework.DynamicFilters/issues/153 + if (DynamicFilterManager.ShouldIgnoreDynamicFilterInterceptor != null && DynamicFilterManager.ShouldIgnoreDynamicFilterInterceptor(interceptionContext)) return; + var queryCommand = interceptionContext.Result as DbQueryCommandTree; if (queryCommand != null) { var context = interceptionContext.DbContexts.FirstOrDefault(); if (context != null) { - // https://github.com/zzzprojects/EntityFramework.DynamicFilters/issues/153 - if (context is HistoryContext) return; - DbExpressionVisitor visitor; #if (USE_CSPACE) // Intercepting CSpace instead of SSpace gives us access to all of the navigation properties diff --git a/src/EntityFramework.DynamicFilters.Shared/DynamicFilterManager.cs b/src/EntityFramework.DynamicFilters.Shared/DynamicFilterManager.cs new file mode 100644 index 0000000..e54ec8e --- /dev/null +++ b/src/EntityFramework.DynamicFilters.Shared/DynamicFilterManager.cs @@ -0,0 +1,15 @@ +using System; +using System.Data.Entity.Infrastructure.Interception; + +namespace EntityFramework.DynamicFilters +{ + /// Manager for dynamic filters. + public static class DynamicFilterManager + { + /// + /// Gets or sets if the DynamicFilterInterceptor should be ignored. + /// + /// True if the DynamicFilterInterceptor should be ignored. + public static Func ShouldIgnoreDynamicFilterInterceptor { get; set; } + } +} diff --git a/src/EntityFramework.DynamicFilters.Shared/EntityFramework.DynamicFilters.Shared.projitems b/src/EntityFramework.DynamicFilters.Shared/EntityFramework.DynamicFilters.Shared.projitems index d72bf1b..203213d 100644 --- a/src/EntityFramework.DynamicFilters.Shared/EntityFramework.DynamicFilters.Shared.projitems +++ b/src/EntityFramework.DynamicFilters.Shared/EntityFramework.DynamicFilters.Shared.projitems @@ -15,6 +15,7 @@ +