是否有可能让 Odata 未绑定“空”功能?

问题描述 投票:0回答:0

我的Odata前缀是

odata/objects/{objectId}
,我想做的是当我调用
GET odata/objects/{a guid}
时,它会返回那个对象

所以我写控制器如下

[HttpGet]
[ODataRoute("")]
public object GetObject([FromODataUri] Guid objectId)
{
    return getObject(objectId);
}

但是当我打电话

GET odata/objects/{a guid}
我会得到
The related entity set or singleton cannot be found from the OData path. The related entity set or singleton is required to serialize the payload

我尝试添加未绑定的“空”函数

var builder = new ODataConventionModelBuilder();
var objects = builder.EntitySet<object>("objects"); // This is used in other places
objects.EntityType.HasKey(w => w.Id);
objects.EntityType.Property(w => w.Id).Name = "id";
builder.Function("").ReturnsFromEntitySet<object>("objects");

但是还是报同样的错误。 出于某种原因,我不想将前缀更改为

odata
并且只是使用了
[ODataRoute("objects({objectId})")]

那么 Odata 中是否可以有“空”未绑定函数?

asp.net asp.net-web-api odata
© www.soinside.com 2019 - 2024. All rights reserved.