I need to create an OData controller with this assign.
http://xxxxxx/odata/mock/Itens(NumContrato='1234',IdItem='10')/Pedidos
ItensController
public class ItensController : ODataController
{
[HttpPost]
[ODataRoute("(NumContrato={NumContrato},IdItem={IdItem})/Pedidos")]
public IQueryable<Pedido> Pedidos([FromODataUri] string NumContrato, [FromODataUri] string IdItem)
{
... do something
}
}
WebApiConfig.cs
...
config.Routes.MapODataServiceRoute(
"ODataRoute",
"odata/mock",
model: GetModel(),
new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
...
public static IEdmModel GetModel()
{
ODataModelBuilder builder = new ODataConventionModelBuilder();
...
builder.EntitySet<Dominio.ODataSapFake.Item>("Itens");
builder.EntitySet<Dominio.ODataSapFake.LinhaDeServico>("LinhasDeServicos");
builder.EntitySet<Dominio.ODataSapFake.Pedido>("Pedidos");
var a = builder.Entity<Dominio.ODataSapFake.Item>().Collection.Action("Pedidos");
a.Parameter<string>("NumContrato");
a.Parameter<string>("IdItem");
a.ReturnsCollectionFromEntitySet<Dominio.ODataSapFake.Pedido>("Pedidos");
...
return builder.GetEdmModel();
}
An error occurs when call service.
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code/>
<m:message xml:lang="en-US">
No HTTP resource was found that matches the request URI 'http://localhost:4492/odata/mock/Itens(NumContrato='100',IdItem='00040')/Pedidos'.
</m:message>
<m:innererror>
<m:message>No routing convention was found to select an action for the OData path with template '~/entityset/key/navigation'.
</m:message>
<m:type/>
<m:stacktrace/>
</m:innererror>
</m:error>
Item, that would have solved the issue a lot quicker :)CustomRouteConvention. the docs are pretty good on custom routing learn.microsoft.com/en-us/odata/webapi/routing-abstractPedidos. Just put an elipsis ... to indicate lines of code that are omitted. It sounds like I'm being pedantic but often going through the process to write a good question helps you to resolve the issue, you can still post it, and you can post your solution and you will still draw commentary.