-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query cache makes query filter Func irrelevant after first execution #4508
Comments
Should be fixed in upcoming V6 release. Anyway, I do not recommend to make query filter very dynamic. It will cause that translated query cache will not hit and queries will be translated again and again. |
Thanks! I've stumbled upon this as i really have another potential bug to report. (I'm making a simplified example right now for ticket) Is there a way to maybe only disable query cache inside a query filter only on those specific situations so i would not need to disable query caching througout the whole system? |
Can you show your real query filter? |
I don't have the full version that causes a bug. I tried joining my entity in query filter against permissions, but it has some flaws. Then i tried using assembly scanning and then interface-based association defining approach. If i have, let's say "Post" entity and it implements "IHasPermissions", then it must define property of "List Permissions", but it will not have attributes defining the association. This is being done during DataConnection initialization through assembly scanning. That almost worked, but then we have a requirement that it's not always the primary key that is used for permission linking. So i may not want to use "Post.Id" for linking with permissions, but "Post.PostType.Id" for example. (assuming we have PostType entity as well) I'll have a simplified example soon. :) |
Describe your issue
When query filter is defined for an entity, then the contents of the query filter is only used once. The query filter Func is executed, but it is not being used when SQL is generated.
Below is example code that uses Random in query filter Func. Whether the caching is enabled or disabled, the random number is always generated and printed out from the query filter Func. But when SQL is composed, it is always containing only the first generated number when caching is enabled.
Steps to reproduce
Following code defines query filter that uses Random to add a WHERE condition to a query. The Random is also printed out from the query filter to show that the query filter Func is being executed. The code prints out SQL text 3 times. On the top, it has flag to enable/disable caching.
When caching is enabled, it shows different random numbers generated for each SQL, but the SQL itself is still containing the old (first) number. When caching is disabled, freshly generated number is always used in SQL text.
Environment details
Linq To DB
version: 5.4.1Database (with version): SQLite
ADO.NET Provider (with version): System.Data.SQLite.Core 1.0.118
Operating system: Windows 11
.NET Version: 8.0
The text was updated successfully, but these errors were encountered: