odata web api use .netcore 3.1
and
Microsoft.AspNetCore.OData 7.4.1
and
Microsoft.EntityFrameworkCore.Cosmos 7.4.1
url like this
odata/MyEntitys?$filter=status eq MemberStatus'd100000001'&$top=50&$select=id&$count=true
and the odata web api error
{"error":{"code":"","message":"The query specified in the URI is not valid. Unrecognized 'Edm.String' literal 'MemberStatus'd100000001'' at '16' in 'memberStatus eq MemberStatus'd100000001''.","details":[,"innererror":{"message":"Unrecognized 'Edm.String' literal 'MemberStatus'd100000001'' at '16' in 'memberStatus eq MemberStatus'd100000001''.","type":"Microsoft.OData.ODataException","stacktrace":" at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseTypedLiteral(ExpressionLexer lexer, IEdmTypeReference targetTypeReference, String targetTypeName)\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.TryParseLiteral(ExpressionLexer lexer)\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParsePrimaryStart()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParsePrimary()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseUnary()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseMultiplicative()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseAdditive()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseComparison()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseLogicalAnd()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseLogicalOr()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseExpression()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseExpressionText(String expressionText)\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseFilter(String filter)\r\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilterImplementation(String filter, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)\r\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilter()\r\n at Microsoft.AspNet.OData.Query.FilterQueryOption.get_FilterClause()\r\n at Microsoft.AspNet.OData.Query.Validators.FilterQueryValidator.Validate(FilterQueryOption filterQueryOption, ODataValidationSettings settings)\r\n at Microsoft.AspNet.OData.Query.FilterQueryOption.Validate(ODataValidationSettings validationSettings)\r\n at Microsoft.AspNet.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\r\n at Microsoft.AspNet.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)\r\n at Microsoft.AspNet.OData.EnableQueryAttribute.ValidateQuery(HttpRequest request, ODataQueryOptions queryOptions)\r\n at Microsoft.AspNet.OData.EnableQueryAttribute.CreateAndValidateQueryOptions(HttpRequest request, ODataQueryContext queryContext)\r\n at Microsoft.AspNet.OData.EnableQueryAttribute.<>c__DisplayClass1_0.<OnActionExecuted>b__1(ODataQueryContext queryContext)\r\n at Microsoft.AspNet.OData.EnableQueryAttribute.ExecuteQuery(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, Func`2 modelFunction, IWebApiRequestMessage request, Func`2 createQueryOptionFunction)\r\n at Microsoft.AspNet.OData.EnableQueryAttribute.OnActionExecuted(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, IWebApiRequestMessage request, Func`2 modelFunction, Func`2 createQueryOptionFunction, Action`1 createResponseAction, Action`3 createErrorAction)"}}}
if use the full class type like this
odata/MyEntitys?$filter=status eq OdataWebApi.Models.MemberStatus'd100000001'&$top=50&$select=id&$count=true
then the error is
System.InvalidCastException: Invalid cast from 'System.Int32' to 'OdataWebApi.Models.MemberStatus'. at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider) at System.Int32.System.IConvertible.ToType(Type type, IFormatProvider provider) at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) at System.Convert.ChangeType(Object value, Type conversionType) at Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter`2.Sanitize[T](Object value) at Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter`2.<>c__DisplayClass3_0`2.b__0(Object v) at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.QuerySqlGenerator.GenerateJToken(Object value, CoreTypeMapping typeMapping) at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.QuerySqlGenerator.VisitSqlConstant(SqlConstantExpression sqlConstantExpression) at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.SqlExpressionVisitor.VisitExtension(Expression extensionExpression) at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.QuerySqlGenerator.VisitSqlBinary(SqlBinaryExpression sqlBinaryExpression) at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.SqlExpressionVisitor.VisitExtension(Expression extensionExpression) at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.QuerySqlGenerator.VisitSelect(SelectExpression selectExpression) at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.SqlExpressionVisitor.VisitExtension(Expression extensionExpression) at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.QuerySqlGenerator.GetSqlQuery(SelectExpression selectExpression, IReadOnlyDictionary`2 parameterValues) at Microsoft.EntityFrameworkCore.Cosmos.Query.Internal.CosmosShapedQueryCompilingExpressionVisitor.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync() at Microsoft.AspNetCore.Mvc.Infrastructure.AsyncEnumerableReader.ReadInternal[T](Object value) at Microsoft.AspNetCore.Mvc.Infrastructure.AsyncEnumerableReader.ReadInternal[T](Object value) at Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor.ExecuteAsyncEnumerable(ActionContext context, ObjectResult result, Object asyncEnumerable, Func`2 reader) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker) at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
public enum MemberStatus { d100000000 = 100000000, d100000001 = 100000001 } public MyEntity { public Guid id{get;set;} public MemberStatus? memberStatus { get; set; } }