我在asp.net core 2中开发了一个Web api,端点如下
现在我想在其中实现odata v4并要求使用以下端点
但是尝试时出现以下错误
InvalidOperationException:路径模板“ values / action1”位于 控制器“值”中的操作“ Method1”不是有效的OData 路径模板。找不到细分“值”的资源。
我的启动类如下
var odataBuilder = new ODataConventionModelBuilder();
odataBuilder.EntitySet<User>("values/action1");
app.UseMvc(routebuilder =>
{
routebuilder.Count().Filter().OrderBy().Expand().Select().MaxTop(null);
routebuilder.MapODataServiceRoute(routeName: "_api", routePrefix: "_api", model: odataBuilder.GetEdmModel());
routebuilder.EnableDependencyInjection();
});
控制器是
[Authorize]
[EnableQuery]
[Route("api/[controller]")]
[ODataRoutePrefix("values")]
public class ValuesController : ODataController
{
[HttpGet("action1")]
[ODataRoute("action1")]
public string Method1()
{
return "Method 1";
}
[HttpGet("action1/TaskB")]
[ODataRoute("action1/TaskB")]
public string Method2()
{
return "Method 2";
}
[HttpGet("action1/{ID}/TaskB")]
[ODataRoute("action1/{ID}/TaskB")]
public string Method3(int ID)
{
return string+ID;
}
}
如何启用上述路线?