When not using odata routing, actions with a $search specified throw "Unable to cast object of type 'System.Linq.Expressions.ConstantExpression' to type 'System.Linq.Expressions.MethodCallExpression'." at AutoMapper.AspNet.OData.LinqExtensions.ToSearchExpression[T](SearchQueryOption filterOption, HandleNullPropagationOption handleNullPropagation, TimeZoneInfo timeZone). This is due to no binder being found, but there is no obvious way to provide a search binder other than the workaround below.
There are cases when $search may want to search across info on the entity, and ISearchBinder only has access to a dto.
I have a couple use cases for this request:
"Unable to cast object of type 'System.Linq.Expressions.ConstantExpression' to type 'System.Linq.Expressions.MethodCallExpression'." at AutoMapper.AspNet.OData.LinqExtensions.ToSearchExpression[T](SearchQueryOption filterOption, HandleNullPropagationOption handleNullPropagation, TimeZoneInfo timeZone)
. This is due to no binder being found, but there is no obvious way to provide a search binder other than the workaround below.It looks like OData code handles it here: https://github.com/OData/AspNetCoreOData/blob/9225d1eba1601bf1470b7e611cdd595fa479dbfc/src/Microsoft.AspNetCore.OData/Query/ODataQueryOptions.cs#L380 or here https://github.com/OData/AspNetCoreOData/blob/9225d1eba1601bf1470b7e611cdd595fa479dbfc/src/Microsoft.AspNetCore.OData/Query/Query/SearchQueryOption.cs#L136
I found this workaround for now but it's ugly: Search binder that always returns true (any actual filtering must be done manually in controller):
Registration: