Comments (7)
Thanks @a-ney. I just wanted to make sure this was independent of [EnableQuery]
itself. Hopefully the OData team will have more information to share with you about this.
In the meantime, you might want to rename your issue to remove the coupling with [EnableQuery]
since it happens regardless of it.
from aspnetcoreodata.
Stacktrace say's it's because of EnableQuery attribute on my GET action which uses it's own FilterBinder instead of CustomFilterBinder.
Does it work fine if you remove the [EnableQuery]
attribute and manually handle a ODataQueryOptions<T>
instead?
from aspnetcoreodata.
@julealgon No, exception is the same.
Microsoft.OData.ODataException: An unknown function with name 'custom' was found. This may also be a function import or a key lookup on a navigation property, which is not allowed.
at Microsoft.OData.UriParser.FunctionCallBinder.GetUriFunctionSignatures(String functionCallToken, Boolean enableCaseInsensitive)
at Microsoft.OData.UriParser.FunctionCallBinder.BindAsUriFunction(FunctionCallToken functionCallToken, List`1 argumentNodes)
at Microsoft.OData.UriParser.FunctionCallBinder.BindFunctionCall(FunctionCallToken functionCallToken)
at Microsoft.OData.UriParser.MetadataBinder.BindFunctionCall(FunctionCallToken functionCallToken)
at Microsoft.OData.UriParser.MetadataBinder.Bind(QueryToken token)
at Microsoft.OData.UriParser.BinaryOperatorBinder.GetOperandFromToken(BinaryOperatorKind operatorKind, QueryToken queryToken)
at Microsoft.OData.UriParser.BinaryOperatorBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)
at Microsoft.OData.UriParser.MetadataBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)
at Microsoft.OData.UriParser.MetadataBinder.Bind(QueryToken token)
at Microsoft.OData.UriParser.FilterBinder.BindFilter(QueryToken filter)
at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilterImplementation(String filter, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)
at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilter()
at Microsoft.AspNetCore.OData.Query.FilterQueryOption.get_FilterClause()
at Microsoft.AspNetCore.OData.Query.FilterQueryOption.ApplyTo(IQueryable query, ODataQuerySettings querySettings)
at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)
at Microsoft.AspNetCore.OData.Query.ODataQueryOptions`1.ApplyTo(IQueryable query, ODataQuerySettings querySettings)
at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query)
at Microsoft.AspNetCore.OData.Query.ODataQueryOptions`1.ApplyTo(IQueryable query)\r\n
at ... //my action call below
from aspnetcoreodata.
@a-ney the methods (for example, geo.distance) listed in the https://devblogs.microsoft.com/odata/customizing-filter-for-spatial-data-in-asp-net-core-odata-8/ are built-in methods, it means that's supported by default in the OData library, but there's no default binding in the ASP.NET Core side . So, The post is trying to bind the methods to a particular C# method.
Your scenario is different, You want to 'define' a cusomized method that is not defined in the OData. You should use the "customized Uri function" feature. It's listed at https://learn.microsoft.com/en-us/odata/webapi/bind-custom-urifunctions-to-clr-methods.
Here's a version from my side:
public static void AddCustomFunc()
{
FunctionSignatureWithReturnType customStringEdmFunction =
new FunctionSignatureWithReturnType(
EdmCoreModel.Instance.GetInt32(true),
EdmCoreModel.Instance.GetString(true));
MethodInfo customStringMethodInfo = typeof(Extensions).GetMethod("MyCustomMethod", new Type[] { typeof(string) });
const string customMethodName = "custom";
ODataUriFunctions.AddCustomUriFunction(customMethodName, customStringEdmFunction, customStringMethodInfo);
}
public static int MyCustomMethod(string input)
{
// you should replace the codes using your logic
switch (input)
{
case "foo": return 1;
case "bar": return 2;
case "tik": return 3;
case "tok": return 4;
default: return 0;
}
}
Then, call 'AddCustomFunc' some place in 'Program.cs' before call using middleware. Then it should work (you don't need to customize the IFilterBinder);
(Known issue: AddCustomUriFunction uses the 'static' to hold the function mapping, it's not good design and better to refactor it in the ODL 8).
from aspnetcoreodata.
@xuzhg wow, thanks a lot, this is exactly what I needed!
from aspnetcoreodata.
reopen for more discussion about the refactor
from aspnetcoreodata.
@a-ney Can you provide working sample of this?
from aspnetcoreodata.
Related Issues (20)
- NullReference exception generated when using FilterClause.ApplyTo method with open properties in the filter query HOT 2
- Case sensitive issue on ODatadynamic Model HOT 2
- Conflicting routes when using NSwag and OData HOT 6
- Data not loaded correctly in Excel and Power BI Desktop with the use of $expand in OData feed HOT 10
- OData DeepInsert not binding correctly HOT 3
- Strange time zone propagation in the filter HOT 3
- Select query throw an error on a dynamic property dictionary HOT 7
- OData + EfCore Filter dynamic properties HOT 2
- FEATURE REQUEST: be able to conditionally omit properties from response payloads HOT 2
- Missing property error when applying select manually HOT 6
- getting 405 when trying to $batch HOT 18
- `$batch` endpoint doesn't show up in the `$odata` route debugging page
- `ODataBatchMiddleware` should throw when no `ODataBatchHandler` is present
- `ODataBatchMiddleware` documentation doesn't mention `ODataBatchHandler` requirement
- Sorting on a grouped nested dynamic property fails
- $expand fails with DTO - EF cannot translate the query expression HOT 12
- $compute inside $expand not translating $this for single navigations HOT 1
- Issue with Object Expansion After Upgrading AspNetCoreOData HOT 4
- The given model does not contain the type 'System.Object' when using $select with untyped properties HOT 3
- Could not find a property named 'keyName' on type 'MyClass' HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aspnetcoreodata.