EntityFramework-Plus icon indicating copy to clipboard operation
EntityFramework-Plus copied to clipboard

Batch Delete with HasQueryFilter

Open pgrm opened this issue 7 years ago • 16 comments

Hello, we switched from EntityFramework-Plus filter extension to EF Core HasQueryFilter because we started using views, but this again doesn't seem to work with batch delete:

System.Collections.Generic.KeyNotFoundException: The given key '__ef_filter__PROPERTYNAME_0' was not present in the dictionary.

any plans to support the ef-core query filter together with your batch / bulk operations?

Thank you!

pgrm avatar Oct 03 '18 23:10 pgrm

Hello @pgrm ,

Do you think you could provide a project sample with this issue?

It will help my developer investigate the issue more efficiently.

We now always ask for a project sample even if the issue is easy to reproduce. As a free product, we must find some way to save time to offer an overall better experience for everyone and release fixes faster.

You can send it to: [email protected] if you need to keep the source private

Best Regards,

Jonathan


Performance Libraries context.BulkInsert(list, options => options.BatchSize = 1000); Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper PlusLinqToSql Plus

Runtime Evaluation Eval.Execute("x + y", new {x = 1, y = 2}); // return 3 C# Eval FunctionSQL Eval Function

JonathanMagnan avatar Oct 04 '18 00:10 JonathanMagnan

Hello @JonathanMagnan

I totally understand that, unfortunately, currently I don't havea lot of time on my hands to set up a test project. Do you maybe have some sample projects with .net core, where you use those bulk operations? Or even better, some integration tests?

I should be able to modify them with only2 lines of code and you'd already know what exactly causes the issue for me without needing to analyze if I set up everything correctly.

pgrm avatar Oct 04 '18 06:10 pgrm

We just need a simple standalone project that contains the issue that we can easily use to reproduce and test it.

Best Regards,

Jonathan

JonathanMagnan avatar Oct 04 '18 17:10 JonathanMagnan

@JonathanMagnan so I've copied one of your online examples (https://dotnetfiddle.net/R6D5BX) and adjusted it to work with ef core and sqlite so I can show the error. This is the extra line which break everything: https://gist.github.com/pgrm/6e7316a776fbb270b2dbd62caa5fe017#file-brokenbatchdeleteexample-cs-L69 when this line is active I get the error:

Unhandled Exception: System.Collections.Generic.KeyNotFoundException: The given key '__ef_filter__ef_filter_0' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Z.EntityFramework.Plus.BatchDelete.CreateCommand(IQueryable query, IEntityType entity) in C:\Users\Jonathan\Desktop\Z\TFS\EFPlus\Z.EntityFramework.Plus\shared\Z.EF.Plus.BatchDelete.Shared\BatchDelete.cs:line 770

   at Z.EntityFramework.Plus.BatchDelete.Execute[T](IQueryable`1 query) in C:\Users\Jonathan\Desktop\Z\TFS\EFPlus\Z.EntityFramework.Plus\shared\Z.EF.Plus.BatchDelete.Shared\BatchDelete.cs:line 344
   at BrokenBatchDeleteExample.Program.Main() in MY_PATH\BrokenBatchDeleteExample\BrokenBatchDeleteExample\Program.cs:line 20

When I comment it out, it works, however, HasQueryFilter works correctly with other where conditions from EF Core, so I guess there is some parameter missing when the expression is being compiled for the batch delete functionality?

Hope this helps

pgrm avatar Oct 09 '18 22:10 pgrm

Thank you,

The Gist is what we were looking for (https://gist.github.com/pgrm/6e7316a776fbb270b2dbd62caa5fe017)

I will assign a developer to it.

Best Regards,

Jonathan

JonathanMagnan avatar Oct 10 '18 18:10 JonathanMagnan

Hello @pgrm ,

We investigated this issue. We have no found how to generate parameter from the QueryFilter.

Meanwhile, a temporary solution on your side is perhaps maybe only to ignore those filters for the current query with IgnoreQueryFilters See: https://docs.microsoft.com/en-us/ef/core/querying/filters#disabling-filters

We will continue to investigate it to find a way to get those parameter values.

Best Regards,

Jonathan

JonathanMagnan avatar Oct 16 '18 20:10 JonathanMagnan

Btw, a new version will be soon available with a better error message to let people know about using IgnoreQueryFilters.

JonathanMagnan avatar Oct 16 '18 20:10 JonathanMagnan

@JonathanMagnan thx for the update

pgrm avatar Oct 18 '18 15:10 pgrm

Hi @JonathanMagnan

First of all, thank you for this great library. I have tried BatchUpdate and faced a similar exception.

The exception occurs here https://github.com/zzzprojects/EntityFramework-Plus/blob/master/src/shared/Z.EF.Plus.BatchUpdate.Shared/BatchUpdate.cs#L894 because queryContext.ParameterValues is empty.

I think the ParameterValues are not correctly populated here https://github.com/zzzprojects/EntityFramework-Plus/blob/master/src/shared/Z.EF.Plus._Core.Shared/EFCore/IQueryable%60/CreateCommand.cs#L38. Somehow queryContext.ParameterValues are not filled with the values of query filter parameters.

ismcagdas avatar Oct 19 '18 06:10 ismcagdas

Hello @ismcagdas ,

Yes, that's exactly the issue.

That will happen with all our features that require to generate the command on our side.

Perhaps EF Core 2.x has now better method to get the query from (this one was created in early stage of EF Core 1.x)

JonathanMagnan avatar Oct 19 '18 14:10 JonathanMagnan

@JonathanMagnan did you have a chance to take a look into this issue ? I would love to help if I can.

ismcagdas avatar Feb 04 '19 08:02 ismcagdas

Hello @ismcagdas ,

Yes, we got the chance at multiple time but we never find out a way to solve it ;(

So for now, the only solution on your side is to apply IgnoreQueryFilters. We don't wanna apply it on our side by default since it will mislead.

Best Regards,

Jonathan

JonathanMagnan avatar Feb 04 '19 13:02 JonathanMagnan

Thanks a lot.

ismcagdas avatar Feb 04 '19 14:02 ismcagdas

Hi guys, Is there any update about this issue?

se avatar Apr 05 '19 12:04 se

Hello @se ,

We didn't investigate it again. So that's the same status

Yes, we got the chance at multiple time but we never find out a way to solve it ;(

So for now, the only solution on your side is to apply IgnoreQueryFilters. We don't wanna apply it on our side by default since it will mislead.

We will probably try again when the version 3.0 will be out.

JonathanMagnan avatar Apr 05 '19 12:04 JonathanMagnan

The given key '__ef_filter__ef_filter_0' was not present in the dictionary.

I have same problem and its not possible for us to Ignore query filters ... is there any hope to fix this issue soon ?

alirezanet avatar Apr 20 '19 18:04 alirezanet