Skip to content
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 filter for property with conversion #12268

Closed
xperiandri opened this issue Jun 7, 2018 · 4 comments
Closed

Query filter for property with conversion #12268

xperiandri opened this issue Jun 7, 2018 · 4 comments

Comments

@xperiandri
Copy link

xperiandri commented Jun 7, 2018

entity.Property(application => application.AllowedTenants)
      .HasConversion(set => JArray.FromObject(set).ToString(Formatting.None),
                     s => !string.IsNullOrWhiteSpace(s)
                        ? JArray.Parse(s)
                                .Values<string>()
                                .ToHashSet(StringComparer.OrdinalIgnoreCase)
                        : new HashSet<string>(StringComparer.OrdinalIgnoreCase));

//entity.HasQueryFilter(a => a.AllowedTenants.Contains(httpContextAccessor.GetAuthorizedTenant()));
entity.HasQueryFilter(a => EF.Functions.Like(EF.Property<ISet<string>>(a, nameof(a.AllowedTenants)), $"%{httpContextAccessor.GetAuthorizedTenant()}%"));

How to make such a query for a property of ISet<string> which is saved as a string in a database?
And force to be executed in the database.

Of course, I would better execute filter using raw SQL which invokes JSON functions of SQL Server.
But it is impossible as I understand.

@smitpatel
Copy link
Member

@xperiandri - What is specific issue you are hitting? Is query throwing or giving incorrect results or not compiling?
You could use JSON_VALUE function on SQL with user defined functions as described in detail here #11295 (comment)

@ajcvickers
Copy link
Member

EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

@xperiandri
Copy link
Author

Thanks @smitpatel, I will try that.


@ajcvickers which additional details?
It is a general question that you have not covered in documentation!

Property that uses conversions cannot be used in EF.Functions using database store type.
So that I cannot force query condition to be evaluated in a database.

@xperiandri
Copy link
Author

@rowanmiller, could you evaluate this, please.
I haven't found any mention of my case in docs. Have you thought of this case? I mean using EF.Functions with converted property targeting database type for filtering.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants