ZEXSM / OData.QueryBuilder

OData.QueryBuilder - library for creating complex OData queries (OData version 4.01) based on data models with linq syntax.
MIT License
71 stars 31 forks source link

Wrong value in odata query when using nullable enum #105

Open casually-creative opened 1 year ago

casually-creative commented 1 year ago

Let's say you have an enum called Status and an entity with 2 properties. One property is of type Status, and the other is of type nullable Status.

public enum Status
{
    Active   = 0,
    Inactive = 1
}

public class SomeEntity
{
    public Status StatusOne { get; set; }
    public Status? StatusTwo { get; set; }
}

Imagine we now create a query with a filter on these properties like so:

string oDataQuery = new ODataQueryBuilder()
    .For<SomeEntity>("some_entity")
    .ByList()
    .Filter(e =>
        e.StatusOne == Status.Active &&
        e.StatusTwo == Status.Active
    )
    .ToUri()
    .ToString();

The resulting query now contains the proper underlying int value of 0 for StatusOne, while it contains the name of the enum field "Active" for property two:

some_entity?$filter=StatusOne eq 0 and StatusTwo eq 'Active'

I would expect both cases would use the underlying int value. Would love to see a fix for this.

casually-creative commented 9 months ago

Hello @ZEXSM, is this issue getting a fix soon? It's been over a year. Sad to see this repo isn't being maintained anymore :/