Hello, I followed your documentation about Data Filters to create my custom filters, but without success. I need a filter with the support of a list of int values.
Example:
var placeIds = new List<int> { 1, 2, 3, 4, 5 };
I have tried following in my DB context, as suggested at [https://github.com/jcachat/EntityFramework.DynamicFilters])
var values = new List<int> { 1, 2, 3, 4, 5 };
var values2 = new List<int?> { null, 1, 2, 3, 4, 5 };
modelBuilder.Filter(DataFilters.MustHavePlace, (IMustHavePlace p, List<int> placeList) => placeList.Contains(p.PlaceId), values);
modelBuilder.Filter(DataFilters.MayHavePlace, (IMayHavePlace p, List<int?> placeList) => placeList.Contains(p.PlaceId), values2);
When I'll try to run the application, it will always return following exception:
ERROR|Abp.Web.Mvc.Controllers.AbpHandleErrorAttribute|System.NullReferenceException: Object reference not set to an instance of an object.
at EntityFramework.DynamicFilters.DynamicFilterExtensions.SetSqlParameters(DbContext context, DbCommand command)
at EntityFramework.DynamicFilters.DynamicFilterCommandInterceptor.SetDynamicFilterParameterValues(DbCommand command, DbContext context)
at EntityFramework.DynamicFilters.DynamicFilterCommandInterceptor.ReaderExecuting(DbCommand command, DbCommandInterceptionContext`1 interceptionContext)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
What is wrong?
5 Answer(s)
-
0
I haven't tried Contains before. Have you registered filter to ABP (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Data-Filters#DocDefineCustomFilters">http://www.aspnetboilerplate.com/Pages/ ... tomFilters</a>) like Configuration.UnitOfWork.RegisterFilter(...)?
-
0
Yes, I did. If I use the List, it's not working. But if I use only one value, like defined for IMayHaveTenant, it is working.
-
0
Thaen it should be related to DynamicFilters library. Can you ask in it's Githus issues page? Because I did not use Contains before.
-
0
I have opened an issue on DynamicFilters Github page. In my case both IMustHavePlace and IMayHavePlace filters throws null reference exception.
Can you please test and confirm that the Contains() operator works correctly with data filters in the ABP framework? Thank you very much.
#Edit: I also tried to generate a new Module Zero template and implement only those models and interfaces as described in [https://github.com/jcachat/EntityFramework.DynamicFilters/issues/45]). This produce the same error.
-
0
OK, then can you create a Github issue on ABP to not forgot to test it.