我的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 中是否可以有“空”未绑定函数?