zzzprojects / EntityFramework-Classic

Entity Framework Classic is a supported version of the latest EF6 codebase. It supports .NET Framework and .NET Core and overcomes some EF limitations by adding tons of must-haves built-in features.
https://entityframework-classic.net
Other
103 stars 27 forks source link

IDbCommandInterceptor called multiple times on queries with .IncludeOptimizedByPath() #68

Closed JendaPerl closed 6 months ago

JendaPerl commented 6 months ago

If I have a query like this: db.Articles.FirstOrDefault(...) my interceptor only gets called once.

If the query is like this db.Articles.IncludeOptimizedByPath("Something").FirstOrDefault(...) it gets called four times.

While I do understand such LINQ queries send several snippets of SQL to the server, it would be nice to be able to tell they are all part of the same LINQ query. Perhaps you might add some information to the DbCommandInterceptionContext to link those related queries. Or keep the UserState between them

JonathanMagnan commented 6 months ago

Hello @JendaPerl ,

Thank you for this suggestion. While I agree it will be nice, that will currently require way too much modification to make it work correctly. So that's currently impossible for us due to the time involved to make it happen.

Best Regards,

Jon


Sponsorship Help us improve this library

Performance Libraries context.BulkInsert(list, options => options.BatchSize = 1000); Entity Framework ExtensionsDapper Plus

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

JendaPerl commented 6 months ago

It's OK. I can find a workaround :-) I just got scared at first, because I had several IncludeOptimizedByPath() calls on that query at first and the interceptor got called ten times.

If you do some refactoring in those parts later, please consider either sending all the queries to the server in a single batch or give interceptors some way to tie the queries together, but it's definitely not a pressing issue.