NullReferenceException when using Effort in combination with DynamicFilters
merken opened this issue · 3 comments
Hi,
I'm trying to use a transient fake database connection for my unit tests, using Effort.
It seems that, in combination with DynamicFilters, the EffortCommand is incorrectly generated when the DynamicFilter is a list of values.
Consider the following code in the DbContext:
//Filter based on a list fails (generation of WHERE TenantId IN (1))
modelBuilder.Filter("ByTenantIds",
(IHaveATenantId entity, List<byte> currentTenants) => currentTenants.Contains(entity.TenantId),
() => TenantProvider.CurrentTenants?.Select(t => t.Id).ToList() ?? new List<byte>());
modelBuilder.EnableFilter("ByTenantIds", () => TenantProvider.CurrentTenants != null);
When accessing any of the DbSets, thus generating SQL, a NullRef exception occurs on DynamicFilerExtensions.SetParameterList, the Command.CommandText is NULL.
Please find a sample repro-project enclosed to this issue.
Cheers,
M
ConsoleApp2.zip
Hello @merken ,
Honestly, I don't think both libraries are compatible at all
- Effort is a memory provider that use LINQ but doesn't use SQL statement at all.
- EF Dynamic Filter change the SQL statement generated and modify SQL parameter
Let me know if that explains correctly the current issue.
Best Regards,
Jonathan
Hi @JonathanMagnan,
As a workaround for the dynamic filter issue, I've tried disabling all filters and the "ByTenantIds" filter specifically, with the same NullRef exception occurring.
I find it strange that a disabled filter still manages to trigger the error, maybe this is another issue?
ctx.DisableAllFilters();
ctx.DisableFilter("ByTenantIds");
Cheers,
M
It still make sense @merken ,
EF Dynamic Filter always appends some parameter to the SQL. When disabled, a check with a NULL
will be done so the filter doesn't apply.
To easily see it, I recommand you to try and profile the SQL in SQL Server do understand what happen behind the scene.
Best Regards,
Jonathan