That is a DynamicFilter bug.
Our EF provider generates SQL
Code: Select all
SELECT
Extent1.Id,
Extent1.Name,
Extent1.DisplayName,
Extent1.Icon,
Extent1.IsDeleted
FROM MyLanguages Extent1
WHERE (Extent1.IsDeleted = :DynamicFilterParam_000001) OR (:DynamicFilterParam_000002 IS NOT NULL)
then DynamicFilter edits SQL via command interception and produces
Code: Select all
SELECT
Extent1.Id,
Extent1.Name,
Extent1.DisplayName,
Extent1.Icon,
Extent1.IsDeleted
FROM MyLanguages Extent1
WHERE (Extent1.IsDeleted = :DynamicFilterParam_000001)
but doesn't remove DynamicFilterParam_000002 from parameters collection.
Workaround is usage of a command interception. The main point is to sign after DynamicFilter:
1. Please add a new class, which implements IDbCommandInterceptor, to your project to fix the problem with undeleted parameter, for example:
Code: Select all
internal class CommandInterceptor: IDbCommandInterceptor {
public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext) {
}
public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext) {
}
public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) {
}
public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) {
for (int i = command.Parameters.Count - 1; i >= 0; i--) {
var param = command.Parameters[i];
if (!command.CommandText.Contains(":" + param.ParameterName))
command.Parameters.Remove(param);
}
}
public void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) {
}
public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) {
}
}
2. Register our command interceptor. For this, turn off filters of DynamicFilter after the first context creation, execute any simple query using context to make DynamicFilter's command interceptor being employed, then add our command interceptor and turn on filters:
Code: Select all
var context = new ExampleContext();
->
Code: Select all
var context = new ExampleContext();
context.DisableAllFilters();
context.Languages.Any();
System.Data.Entity.Infrastructure.Interception.DbInterception.Add(new CommandInterceptor());
context.EnableAllFilters();