.net core .Net core 2.1输出不工作

.net core .Net core 2.1输出不工作,.net-core,odata,asp.net-core-2.1,.net Core,Odata,Asp.net Core 2.1,我正在尝试为客户实现一个ODataController,它能够为我提供像查询模型一样的uri http://localhost:1234/odata/v1/customers?$top=4 或者使用以下方法根据Id获取一个客户 http://localhost:1234/odata/v1/customers/1 但无论我尝试什么,我都无法将参数传递给控制器上的操作/函数 我的代码是这样的 app.UseMvc(routeBuilder => {

我正在尝试为客户实现一个ODataController,它能够为我提供像查询模型一样的uri
http://localhost:1234/odata/v1/customers?$top=4

或者使用以下方法根据Id获取一个客户

http://localhost:1234/odata/v1/customers/1

但无论我尝试什么,我都无法将参数传递给控制器上的操作/函数

我的代码是这样的

        app.UseMvc(routeBuilder =>
        {
            routeBuilder.Select().Expand().Filter().OrderBy().MaxTop(100).Count();
            routeBuilder.MapODataServiceRoute("ODataRoutes", "odata/v1", modelBuilder.GetEdmModel(app.ApplicationServices));
            routeBuilder.EnableDependencyInjection();
        });
GetedModel
基本上是这样构建模型的:

        builder.EntitySet<Customer>("Customers")
                        .EntityType
                        .Filter() // Allow for the $filter Command
                        .Count() // Allow for the $count Command
                        .Expand() // Allow for the $expand Command
                        .OrderBy() // Allow for the $orderby Command
                        .Page() // Allow for the $top and $skip Commands
                        .Select()// Allow for the $select Command; 
                         .ContainsMany(x => x.Transactions)
                        .Expand();
builder.EntitySet(“客户”)
.EntityType
.Filter()//允许使用$Filter命令
.Count()//允许使用$Count命令
.Expand()//允许使用$Expand命令
.OrderBy()//允许使用$OrderBy命令
.Page()//允许使用$top和$skip命令
.Select()//允许使用$Select命令;
.ContainsMany(x=>x.Transactions)
.Expand();
在控制器本身上,我定义了属性routing

[Produces("application/json")]
[ODataRoutePrefix("v1/[controller]")]
public class CustomersController : ODataController
{

    [EnableQuery]
    public ActionResult<IQueryable<Customer>> GetCustomers()
    {
        try
        {
            return context.Set<Customer>();
        }
        catch (Microsoft.OData.ODataException ex)
        {
            return BadRequest(ex.Message);
        }
    }

    [EnableQuery]
    public ActionResult<Customer> Get([FromODataUri] string id)
    {
        try
        {
            var customer = context.Set<Customer>().Where(r => r.CustomerId == id).SingleOrDefault();
[产生(“应用程序/json”)]
[ODataRoutePrefix(“v1/[controller]”)
公共类CustomerController:ODataController
{
[启用查询]
公共操作结果GetCustomers()
{
尝试
{
返回context.Set();
}
捕获(Microsoft.OData.ODataException ex)
{
返回请求(例如消息);
}
}
[启用查询]
public ActionResult Get([FromODataUri]字符串id)
{
尝试
{
var customer=context.Set();

当我有uri=
http://localhost:1234/odata/v1/customers/1
它被传递到函数
Get([FromODataUri]string id)
但是id的值总是空的。我尝试过定义
[ODataRoute({id}”)]
,但即使这样也不起作用。

OData与控制器名称一起工作。 将
[ODataRoutePrefix(“v1/[controller]”)更改为
[ODataRoutePrefix(“v1/Customers”)]


string id
更改为
string key

我不确定您的建议是否正确。
[controller]
将替换为实际的控制器名称。我还认为参数名称也是如此。存在使用
[controller]的github问题
在ODataRoute前缀中表示它不工作,但除此之外,您是否可以引用任何显示在ODataRoute中工作的
[controller]
?odata路由约定的源代码使用
entityset/key
语法,我看不到对
[controller]的支持
在OData路由模板中。即使是
entityset
也用于匹配操作方法名称,而不是模板。我正在建立一个帖子或GH问题列表,尝试在OData路由模板中使用
[controller]
:请随意添加您的帖子,或者在点击此按钮时发表评论。