-
Notifications
You must be signed in to change notification settings - Fork 473
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
Question: configure EF where clause for open type $filter #1909
Comments
@engenb You can try looking at the FilterBinder code and inject your own FilterBinder through dependency injection that just handles the open properties differently. |
In your case you likely want to extend the OData translates individual parts of the Your custom function call in the expression tree then needs to be translated via a IMethodCallTranslator via DbFunction. dotnet/efcore#11295 |
@Danielku15 I know this is an old ticket, but there doesn't seem to be many examples overriding the FilterBinder class. Once you've created your custom variant, how would you register it? |
Phew, never tried it actively, and it's been a long time (we're not using this lib anymore 😅 ). But the FilterBinder is registered within the dependency injection container of OData: WebApi/src/Microsoft.AspNet.OData.Shared/Extensions/ContainerBuilderExtensions.cs Line 90 in 0338075
This OData lib comes with an own DI system due to the compatibility between ASP.net Web API and ASP.net core variants. So it might depend how you register it correctly but in ASP.net core ()Microsoft.Extensions.DependencyInjection) classical way you would just register something like |
Hello,
I have a model with an open type, represented as
IDictionary<string, object> Data { get; set; }
. In EF, this property has a converter defined, to deserialize/serialize the property as JSON when it is written/read to/from the database as such:Generally speaking, this is working great, except a new requirement requires me to fetch records based on a dynamic property, if it exists.
OData isn't going to know how to translate the $filter clause for this because it doesn't know I'm storing this property as JSON. I was wondering if there's a point where I can configure how the EF where clause is generated for the $filter param.
My ideal scenario:
A point to configure how to filter open types. Fall back on default behavior unless the filtered property doesn't match any static properties in the model. If the property isn't static, I'd like to generate my own where clause that utilizes raw SQL so I can utilize MSSQL JSON_VALUE in the where clause for that property.
Not-so-ideal scenario:
I extend ODataQueryOptions to have more control over how the $filter is applied to the IQueryable. I'm hoping this isn't the way I need to go as this class has a lot of logic in it, so I'm hoping someone more experienced with this project will have a better idea.
Thanks!
The text was updated successfully, but these errors were encountered: