ASP.. Core 5 OData:请求单个属性未找到



我在。net 5上使用Microsoft.AspNetCore.OData创建一个OData服务。

在我的EDM模型中,有一个基于以下实体类型的报告集合:

<EntityType Name="Report">
<Key>
<PropertyRef Name="ReportId" />
</Key>
<Property Name="ReportId" Type="Edm.String" Nullable="false" />
<Property Name="ReportName" Type="Edm.String" />
<NavigationProperty Name="Units" Type="Collection(DataModelBase.UnitInfo)" />
<NavigationProperty Name="Data" Type="Collection(DataModel.EntityInfo)" />
</EntityType>

当我发送请求serviceRoot/Reports('1')时,我可以看到ReportId='1'正确显示的报告。

但是,如果我尝试serviceRoot/Reports('1')/ReportId,它应该根据OData基本教程工作,我得到一个404未发现错误。

我的应用配置如下(f#):

app.UseRouting()
.UseEndpoints(fun endpointBuilder ->
endpointBuilder.MapControllers() |> ignore;
endpointBuilder.Select().Expand().Filter().Count().OrderBy() |> ignore;
endpointBuilder.MapODataRoute("odata","odata",edmModel) |> ignore
)|> ignore

和服务:

services.AddControllers(fun mvcOptions -> mvcOptions.EnableEndpointRouting <- true) |> ignore;
services.AddOData() |> ignore

谁能告诉我我错过了什么?

经过一番调查,我想我有了问题的答案:参数路由不是像我期望的那样自动生成的。你需要自己实现路由的控制器。

最新更新