diff --git a/src/DelegateBenchmark/App.config b/src/DelegateBenchmark/App.config
new file mode 100644
index 0000000..d468254
--- /dev/null
+++ b/src/DelegateBenchmark/App.config
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/DelegateBenchmark/DelegateBenchmark.csproj b/src/DelegateBenchmark/DelegateBenchmark.csproj
new file mode 100644
index 0000000..d413af9
--- /dev/null
+++ b/src/DelegateBenchmark/DelegateBenchmark.csproj
@@ -0,0 +1,160 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {8262C3EC-B191-4E3F-915B-3BB4433310DE}
+ Exe
+ Properties
+ DelegateBenchmark
+ DelegateBenchmark
+ v4.6
+ 512
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+ ..\packages\BenchmarkDotNet.0.10.12\lib\net46\BenchmarkDotNet.dll
+
+
+ ..\packages\BenchmarkDotNet.Core.0.10.12\lib\net46\BenchmarkDotNet.Core.dll
+
+
+ ..\packages\BenchmarkDotNet.Toolchains.Roslyn.0.10.12\lib\net46\BenchmarkDotNet.Toolchains.Roslyn.dll
+
+
+ ..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll
+
+
+ ..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll
+
+
+ ..\packages\Microsoft.CodeAnalysis.Common.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.dll
+
+
+ ..\packages\Microsoft.CodeAnalysis.CSharp.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll
+
+
+ ..\packages\Microsoft.DotNet.InternalAbstractions.1.0.0\lib\net451\Microsoft.DotNet.InternalAbstractions.dll
+
+
+ ..\packages\Microsoft.DotNet.PlatformAbstractions.1.1.1\lib\net451\Microsoft.DotNet.PlatformAbstractions.dll
+
+
+ ..\packages\Microsoft.Win32.Registry.4.3.0\lib\net46\Microsoft.Win32.Registry.dll
+
+
+
+ ..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll
+ True
+
+
+ ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll
+ True
+
+
+
+
+ ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll
+
+
+
+
+ ..\packages\System.Diagnostics.FileVersionInfo.4.3.0\lib\net46\System.Diagnostics.FileVersionInfo.dll
+
+
+ ..\packages\System.Diagnostics.StackTrace.4.3.0\lib\net46\System.Diagnostics.StackTrace.dll
+
+
+ ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll
+ True
+
+
+ ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll
+
+
+ ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll
+
+
+
+
+ ..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll
+
+
+ ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net46\System.Security.Cryptography.Algorithms.dll
+ True
+
+
+ ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll
+
+
+ ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll
+
+
+ ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net46\System.Security.Cryptography.X509Certificates.dll
+ True
+
+
+ ..\packages\System.Text.Encoding.CodePages.4.3.0\lib\net46\System.Text.Encoding.CodePages.dll
+
+
+ ..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll
+
+
+ ..\packages\System.Threading.Thread.4.3.0\lib\net46\System.Threading.Thread.dll
+
+
+ ..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll
+
+
+
+
+ ..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll
+
+
+ ..\packages\System.Xml.XmlDocument.4.3.0\lib\net46\System.Xml.XmlDocument.dll
+
+
+ ..\packages\System.Xml.XPath.4.3.0\lib\net46\System.Xml.XPath.dll
+
+
+ ..\packages\System.Xml.XPath.XDocument.4.3.0\lib\net46\System.Xml.XPath.XDocument.dll
+
+
+
+
+
+
+
+
+
+
+ Designer
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/DelegateBenchmark/DelegateInvoking.cs b/src/DelegateBenchmark/DelegateInvoking.cs
new file mode 100644
index 0000000..8c7583c
--- /dev/null
+++ b/src/DelegateBenchmark/DelegateInvoking.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Data.Entity;
+using System.Linq;
+using BenchmarkDotNet.Attributes;
+
+namespace DelegateBenchmark
+{
+ public class DelegateInvoking
+ {
+ private readonly MulticastDelegate _multicastDelegate;
+
+ private readonly Func _funcDelegate;
+
+ private readonly DbContext _dbContext;
+
+ public DelegateInvoking()
+ {
+ Func condition = () => { return false; };
+
+ this._multicastDelegate = (MulticastDelegate) condition;
+ this._funcDelegate = (DbContext dbcontext) => { return condition(); };
+ this._dbContext = new DbContext("default");
+ }
+
+ [Benchmark]
+ public bool MulticastDelegate_DynamicInvoke()
+ {
+ var func = this._multicastDelegate;
+ var parameters = func.Method.GetParameters();
+ if (parameters.Any())
+ return (bool) func.DynamicInvoke(_dbContext);
+
+ return (bool) func.DynamicInvoke();
+ }
+
+ [Benchmark]
+ public bool FunDelegate_Invoke()
+ {
+ return this._funcDelegate.Invoke(this._dbContext);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/DelegateBenchmark/Program.cs b/src/DelegateBenchmark/Program.cs
new file mode 100644
index 0000000..199f5f4
--- /dev/null
+++ b/src/DelegateBenchmark/Program.cs
@@ -0,0 +1,14 @@
+using System;
+using BenchmarkDotNet.Running;
+
+namespace DelegateBenchmark
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ BenchmarkRunner.Run();
+ Console.ReadLine();
+ }
+ }
+}
diff --git a/src/DelegateBenchmark/Properties/AssemblyInfo.cs b/src/DelegateBenchmark/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..40f6906
--- /dev/null
+++ b/src/DelegateBenchmark/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("DelegateBenchmark")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("DelegateBenchmark")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2018")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("8262c3ec-b191-4e3f-915b-3bb4433310de")]
+
+// 程序集的版本信息由下列四个值组成:
+//
+// 主版本
+// 次版本
+// 生成号
+// 修订号
+//
+// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
+//通过使用 "*",如下所示:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/src/DelegateBenchmark/packages.config b/src/DelegateBenchmark/packages.config
new file mode 100644
index 0000000..b77a3a1
--- /dev/null
+++ b/src/DelegateBenchmark/packages.config
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/EntityFramework.DynamicFilters.sln b/src/EntityFramework.DynamicFilters.sln
index ba581e0..15a390e 100644
--- a/src/EntityFramework.DynamicFilters.sln
+++ b/src/EntityFramework.DynamicFilters.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
-VisualStudioVersion = 15.0.27004.2005
+VisualStudioVersion = 15.0.27130.2020
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityFramework.DynamicFilters", "EntityFramework.DynamicFilters\EntityFramework.DynamicFilters.csproj", "{56E36AD1-E675-42F0-96CB-7F475E05E491}"
EndProject
@@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Z.Lab", "Z.Lab\Z.Lab.csproj
EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Z.Lab.VB", "Z.Lab.VB\Z.Lab.VB.vbproj", "{6D24EDDC-96C8-495F-B1D2-0BFB74654173}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DelegateBenchmark", "DelegateBenchmark\DelegateBenchmark.csproj", "{8262C3EC-B191-4E3F-915B-3BB4433310DE}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -47,6 +49,10 @@ Global
{6D24EDDC-96C8-495F-B1D2-0BFB74654173}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D24EDDC-96C8-495F-B1D2-0BFB74654173}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D24EDDC-96C8-495F-B1D2-0BFB74654173}.Release|Any CPU.Build.0 = Release|Any CPU
+ {8262C3EC-B191-4E3F-915B-3BB4433310DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {8262C3EC-B191-4E3F-915B-3BB4433310DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {8262C3EC-B191-4E3F-915B-3BB4433310DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {8262C3EC-B191-4E3F-915B-3BB4433310DE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/src/EntityFramework.DynamicFilters/DynamicFilterExtensions.cs b/src/EntityFramework.DynamicFilters/DynamicFilterExtensions.cs
index 39305cd..88272a2 100644
--- a/src/EntityFramework.DynamicFilters/DynamicFilterExtensions.cs
+++ b/src/EntityFramework.DynamicFilters/DynamicFilterExtensions.cs
@@ -22,13 +22,15 @@ public static class DynamicFilterExtensions
/// Key: Filter Name
/// Value: The parameters for the filter
///
- private static ConcurrentDictionary _GlobalParameterValues = new ConcurrentDictionary();
+ private static ConcurrentDictionary _GlobalParameterValues =
+ new ConcurrentDictionary();
///
/// Key: The DbContext to which the scoped parameter values belong
/// Values: A dictionary defined as _GlobalParameterValues that contains the scoped parameter values for the DbContext
///
- private static ConcurrentDictionary> _ScopedParameterValues = new ConcurrentDictionary>();
+ private static ConcurrentDictionary> _ScopedParameterValues =
+ new ConcurrentDictionary>();
///
/// These properties are used to prevent adding conditions to the sql queries to check to see if filters are
@@ -88,9 +90,14 @@ public static void ResetDynamicFilters(this DbModelBuilder modelBuilder)
/// If not null, specifies a globally scoped value for this parameter
///
[Obsolete("Use modelBuilder.Filter() instead")]
- public static EntityTypeConfiguration Filter(this EntityTypeConfiguration config,
- string filterName, string columnName, object globalValue = null)
- where TEntity : class
+ public static EntityTypeConfiguration Filter(this EntityTypeConfiguration config, string filterName,
+ string columnName, object globalValue = null) where TEntity : class
+ {
+ return EntityFilter(config, filterName, columnName, globalValue != null ? _ => globalValue : (Func) null);
+ }
+
+ private static EntityTypeConfiguration EntityFilter(EntityTypeConfiguration config, string filterName, string columnName,
+ Func globalValue) where TEntity : class
{
filterName = ScrubFilterName(filterName);
var filterDefinition = new DynamicFilterDefinition(Guid.NewGuid(), filterName, null, columnName, typeof(TEntity), null);
@@ -119,31 +126,37 @@ public static EntityTypeConfiguration Filter(this EntityTypeCo
///
#pragma warning disable 618
[Obsolete("Use modelBuilder.Filter() instead")]
- public static EntityTypeConfiguration Filter(this EntityTypeConfiguration config,
- string filterName, Expression> path, Func