AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

Minimal APIs Cannot Expand Single Entity

Open andrew-turrentine opened this issue 1 month ago • 2 comments

With minimal APIs, I cannot figure out how to have $expand work properly when the $expand is one a single entity and not a collection.

If I use .FirstOrDefault(...) then I get expected results and a valid entity - $select even works.

However, if I try to use SingleResult<T> with .Where(...) for $expand then I start to get errors related to conversions or the wrapped type not being present in the model

The given model does not contain the type 'Microsoft.AspNetCore.OData.Results.SingleResult1[[Turpy.Nexus.Data.Entities.Organization, Turpy.Nexus.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]'. (Parameter 'elementClrType')

Can someone give me an example of how to accomplish this or check if this is a bug? I can have it return a collection of 1 item but that is not very clean or performant.

andrew-turrentine avatar Dec 09 '25 03:12 andrew-turrentine