Search code examples
c#odata

Cannot filter query by child object enum field in OData


I have ASP.NET Core WebApi and endpoint with enabled odata query. Endpoint returns IQueryable<MyDataResponse> when MyDataResponse contains many child objects and creates from MyDataEntity with LINQ Select field by field in endpoint.

Most of odata queries with $filter works fine. HttpGet queries with $filter by all fields, all childObject/fields and enums works good. Except $filter by childObject/EnumField, it's falls with 500 error:

{
    "status": 500,
    "traceId": "00-deecb3ed2db91a408a21b51f80bf95e4-96af3e47d32e8e4c-00",
    "errors": {
        "message": [
            "Exception has been thrown by the target of an invocation."
        ]
    }
}

I tried to pull out childObject/EnumField as parent field and it works! But i need access by childObject/EnumField.

Can you explain why it falls with 500 server error? And how i can fix it?


Solution

  • I couldn't figure out why the error is falling. But i found request which works correct - $expand=childType($filter=EnumField eq 'EnumValue')