odata - 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
谁能告诉我我错过了什么?
解决方案
经过一番调查,我想我的问题有了答案:参数路由不会像我预期的那样自动生成。您需要自己实现路由的控制器。
推荐阅读
- asp.net-web-api - 无法使用 ReadAsAsync 获取对象
- javascript - 如何在鼠标悬停时播放音频?
- laravel - VueJs 不适用于 Laravel 5.6
- iphone - 使用 AVFoundation 在 Iphone 照片捕获中图像捕获比闪存慢
- mysql - 执行 CMD 命令会导致 Mariadb 容器停止
- javascript - javascript在textarea中获取选定的文本
- java - java.lang.IllegalStateException:驱动程序可执行文件不存在:尝试通过 Selenium、ChromeDriver 和 Chrome 执行测试时
- javascript - 操作 Promise 返回的对象和数组
- linux - 在 bash 脚本中,count1 = `cat $affected_ip|wc -l`;echo $count1;
- yii2 - Yii2 : 设置访问控制匹配回调