You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've a service that builds a dynamic query WHERE condition based on some filters.
I'm trying to use your library to build one of those filter, related to an array of enum values, but I'm getting this Exception at runtime:
The type MyProject.Api.Data.Models.OperationType must have at least one public property.
The user can select one or more of those values and so the WHERE condition has to be built using OR.
The MyProject.Api.Data.Models.OperationType is an enum type defined as follows:
...if(filter.OperationTypes?.Any()==true){// Conversion from API enum model to EF enum modelvaroperationTypes= filter.OperationTypes.Select(c => Enum.Parse<Data.Models.OperationType>(c.ToString(),true)).ToArray();// Call to AsQueryableValues that causes the ExceptionvarqueryableValues= _dbContext.AsQueryableValues(operationTypes);query= query.Where(x => x.Movements.OperationType !=null&& queryableValues.Contains(x.Movements.OperationType.Value));}
...
Am I doing something wrong? How am I supposed to use the library with enums?
The text was updated successfully, but these errors were encountered:
Having said that, what if you project your enum as its underlying data type –assuming byte per your stub– and use that instead? like this:
...if(filter.OperationTypes?.Any()==true){// Conversion from API enum model to EF enum model// *** Notice the cast to byte ***varoperationTypes= filter.OperationTypes.Select(c => Enum.Parse<Data.Models.OperationType>(c.ToString(),true)).Select(i =>(byte)i);// Call to AsQueryableValues that causes the ExceptionvarqueryableValues= _dbContext.AsQueryableValues(operationTypes);// *** Notice the cast to byte ***query= query.Where(x => x.Movements.OperationType !=null&& queryableValues.Contains((byte)x.Movements.OperationType.Value));}
...
I've a service that builds a dynamic query
WHERE
condition based on some filters.I'm trying to use your library to build one of those filter, related to an array of enum values, but I'm getting this Exception at runtime:
The user can select one or more of those values and so the
WHERE
condition has to be built usingOR
.The
MyProject.Api.Data.Models.OperationType
is an enum type defined as follows:My actual code for building the query is this:
Am I doing something wrong? How am I supposed to use the library with enums?
The text was updated successfully, but these errors were encountered: