Is it possible to achieve the following route with Asp.Net Core 3.1 and Microsoft.AspNetCore.OData version 7.3.0:
/ParentEntity({id})/Children(OnlyActive={onlyActive})
What I've achieved:
The controller's method:
[HttpGet]
[ODataRoute("ParentEntity({id})/Children")]
public async Task<IActionResult> Children([FromODataUri] string id)
{
// some data fetching operations.
}
With the following model configuration:
builder.EntityType<ParentEntity>().Function("Children")
.ReturnsCollectionFromEntitySet<ChildEntity>("ChildEntity");
Works fine and I'm can get id parameter in Children method.
But when I'm trying to do something like:
[HttpGet]
[ODataRoute("ParentEntity({id})/Children(OnlyActive={onlyActive})")]
public async Task<IActionResult> Children([FromODataUri] string id, [FromODataUri] bool onlyActive)
{
// some data fetching operations.
}
With model configuration:
FunctionConfiguration getFunc = builder.EntityType<ParentEntity>().Function("Children")
.ReturnsCollectionFromEntitySet<ChildEntity>("ChildEntity");
getFunc.Parameter<bool>("OnlyActive");
I'm getting the error:
Microsoft.OData.ODataException: 'Bad Request - Error in query syntax'
Is it possible to use Odata functions this way? Or should I try another approach?
question from:
https://stackoverflow.com/questions/65885689/asp-net-core-3-1-odata-doesnt-work-with-attribute-routing-and-function-with-par 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…