OData ASP.NET Core Web API Get方法-传递多个参数

时间:2019-01-12 14:35:47

标签: c# odata asp.net-core-webapi

我有一个ASP.NET Core Web API OData 4函数,其中传递了两个参数并配置了路由,如下所示。

[HttpGet]
[EnableQuery]
[ODataRoute("AApp({id},{name})")]
public IActionResult Get([FromODataUri]int id, [FromODataUri]string name)
{
     return Ok(context.AApp.AsQueryable().FirstOrDefault(x => x.AppId == id && 
          x.App == name));
}

我已经创建了构建器函数,并在其中传递了两个参数,如下所示:-

var AAppByIdName = builder.Function("AApp");
AAppByIdName.Parameter<int>("id");
AAppByIdName.Parameter<string>("name");
AAppByIdName.ReturnsCollectionFromEntitySet<AApp>("AApp");

现在,当我运行项目时,出现错误:

  

控制器AApp({id},{name})中的动作Get上的路径模板MyAppController不是有效的OData路径模板。 URI中指定的键数与资源MyNamespace.AspNetCore.Models.AApp的键属性数不匹配。

请提出修复建议,因为我已经创建了功能参数并配置了路由。

0 个答案:

没有答案
相关问题