Linoy.M.K Linoy.M.K - 1 month ago 14
C# Question

Odata with unbound function : The related entity set or singleton cannot be found from the OData path

I am looking to create an unbound function inside ProductController which return entirely different entity(Not related to Product).

[EnableQuery]
public class ProductsController : ODataController
{
[HttpGet]
[ODataRoute("InvokeMyUnBoundFunction(Id={id})")]
public IHttpActionResult InvokeMyUnBoundFunction(int id)
{
TestUnBound testObj= new TestUnBound();
testObj.Name = "Test" + id;
return Ok(testObj);
}
}


and my webApiConfig is

ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Product>("Products");
builder.EntitySet<TestUnBound>("TestUnBounds"); //Its not related to Product.
builder.Function("InvokeMyUnBoundFunction").Returns<TestUnBound>().Parameter<int>("Id");


But when I invoked
http://localhost:port/api/odata/InvokeMyUnBoundFunction(Id=1234)
I got an error message like


"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."


Am I missed any concepts?

Answer

You should use

ReturnsFromEntitySet<TestUnBound> 

instread of

Returns<TestUnBound>
Comments