Closed hmz777 closed 2 years ago
Can you show your AutoMapper
profile for the PatientDTO
?
I believe what you need to do is call ExplicitExpansion
in your Patient
profile.
CreateMap<Patient, PatientDTO>( )
.ForAllMembers( opts => opts.ExplicitExpansion( ) );
The default behavior will expand all of your navigation properties. Setting ExplicitExpansion
will of course mean that a consumer of the API will now have to explicitly expand the navigation properties in order to include those entities in the result set.
Also, as a side note (unrelated to this library) you're currently executing your query synchronously.
Take a look at this issue. In order to get around that you can explicitly call ToListAsync
on the IQueryable
.
[HttpGet]
public async Task<IActionResult> GetPatients(ODataQueryOptions<PatientDTO> options)
{
var queryable = await _context.Patients.GetQueryAsync( mapper, options )
return Ok( await queryable.ToListAsync( ) );
}
@wbuck Thank you! This works as expected. And I appreciate the issue link, I didn't know about this.
This is my first time using AutoMapper with OData, I have a test EFCore API enabled with all the odata features with the following URL:
https://localhost:<port>/odata/patients
Patients
:(The DTO in this situation has the exact same structure as actual DB Entity)
but using
GetQueryAsync
like this:produces this SQL:
while a regular odata action with
EnableQuery
with the same URL:Am I missing something here?