AutoMapper / AutoMapper.Extensions.OData

Creates LINQ expressions from ODataQueryOptions and executes the query.
MIT License
140 stars 38 forks source link

Not working filter operator in on enums #183

Closed petrkasnal closed 1 year ago

petrkasnal commented 1 year ago

Hi,

i was try filter my enum values with in operator.

/entitites?$filter=((MyType in ('Started')))

And i have this error. When i try it on string or int it's working normally. But in enum it's problem. Equal on enum is normally working. Thanks

Message: No generic method 'Contains' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.

Stack trace at System.Linq.Expressions.Expression.FindMethod(Type type, String methodName, Type[] typeArgs, Expression[] args, BindingFlags flags) at System.Linq.Expressions.Expression.Call(Type type, String methodName, Type[] typeArguments, Expression[] arguments) at AutoMapper.Extensions.ExpressionMapping.MapperExtensions.gMapBody|8_1[TDestDelegate](Dictionary2 typeMappings, XpressionMapperVisitor visitor, <>c__DisplayClass8_01& ) at AutoMapper.Extensions.ExpressionMapping.MapperExtensions.MapExpression[TDestDelegate](IConfigurationProvider configurationProvider, LambdaExpression expression, Type typeSourceFunc, Type typeDestFunc, Func3 getVisitor, Func2 shouldConvertMappedBodyToDestType) at AutoMapper.Extensions.ExpressionMapping.MapperExtensions.MapExpression[TDestDelegate](IMapper mapper, LambdaExpression expression, Func3 getVisitor, Func2 shouldConvertMappedBodyToDestType) at AutoMapper.Extensions.ExpressionMapping.MapperExtensions.MapExpression[TDestDelegate](IMapper mapper, LambdaExpression expression) at AutoMapper.AspNet.OData.QueryableExtensions.GetQuery[TModel,TData](IQueryable1 query, IMapper mapper, Expression1 filter, Expression1 queryFunc, IEnumerable1 includeProperties, ProjectionSettings projectionSettings) at AutoMapper.AspNet.OData.QueryableExtensions.GetQueryable[TModel,TData](IQueryable1 query, IMapper mapper, ODataQueryOptions1 options, QuerySettings querySettings, Expression1 filter) at AutoMapper.AspNet.OData.QueryableExtensions.GetQuery[TModel,TData](IQueryable1 query, IMapper mapper, ODataQueryOptions1 options, QuerySettings querySettings) at Application.Handlers.All.AllQueryHandler.Handle(AllQuery request, CancellationToken cancellationToken) in C:\user\workspace\..... 43 at Framework.Mediator.Behaviors.AuthorizationBehaviour2.d3.MoveNext()

BlaiseD commented 1 year ago

Enums should work e.g.

Make sure you're using this version of the expression mapping library. Otherwise post a repro we can execute and recreate the exception.