首页 > 解决方案 > ASP.NET Core 5 OData:请求未找到的单个属性

问题描述

我正在使用 .NET 5 在 .NET 5 上创建 OData 服务Microsoft.AspNetCore.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 Basic Tutorial工作,我会收到 404 not found 错误。

我的应用配置如下(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

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

标签: odataasp.net-core-5.0

解决方案


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


推荐阅读