I'm unable to find information about how to return a single entity using Minimal APIs and OData. All the samples I have found so far only include collections and functions/operations.
What I have tried:
app.MapGet("/api/customers/{id}", (id, ApplicationDbContext db) =>
{
IQueryable<TEntity> query = db
.Customers
.AsNoTracking()
.Where(e => e.Id == id);
return SingleResult.Create(query);
})
.AddODataQueryEndpointFilter()
.WithODataModel(EdmModelBuilder.Model)
.WithODataResult();
Doesn't work, results in an exception that says SingleResult wasn't found in the EDM model.
app.MapGet("/api/customers/{id}", (id, ApplicationDbContext db, ODataQueryOptions<TEntity> queryOptions) =>
{
IQueryable<TEntity> query = db
.Customers
.AsNoTracking()
.Where(e => e.Id == id);
return queryOptions.ApplyTo(query).Cast<Customer>().FirstOrDefault();
})
.WithODataModel(EdmModelBuilder.Model)
.WithODataResult();
This results in an Entity Framework exception, about not being able to map SelectSome to Customer (makes sense).
What is the correct way to do this?
I'm unable to find information about how to return a single entity using Minimal APIs and OData. All the samples I have found so far only include collections and functions/operations.
What I have tried:
Doesn't work, results in an exception that says
SingleResultwasn't found in the EDM model.This results in an Entity Framework exception, about not being able to map
SelectSometoCustomer(makes sense).What is the correct way to do this?