OData support for Int64 key seems to be lacking (I also accept I may be doing something wrong)
Run:
http://localhost/MyTypes(2886753098675309)
Result:
{
"odata.error": {
"code": "",
"message": {
"lang": "en-US",
"value": "The request is invalid."
},
"innererror": {
"message": "The parameters dictionary contains a null entry for parameter 'key' of non-nullable type 'System.Int64' for method 'System.Net.Http.HttpResponseMessage Get(Int64)' in 'System.Web.Http.OData.EntitySetController`2[OdataProblemDemo.Controllers.MyType,System.Int64]'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.",
"type": "",
"stacktrace": ""
}
}
}
And yet it works for an Int32
type definition:
public class MyType
{
public long Key { get; set; }
}
Controller (SHouldn't need decorating with [FromODataUri], but makes no difference):
public class MyTypesController : EntitySetController<MyType, long>
{
protected override MyType GetEntityByKey(long key)
{
return new MyType {Key = key};
}
}
and in global.asax
ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<MyType>("MyTypes");
var model = modelBuilder.GetEdmModel();
GlobalConfiguration.Configuration.Routes.MapODataRoute(
routeName: "OData",
routePrefix: null,
model: model);
Comments: I still couldn't repro this. The URL with 'L' suffix works fine on my box. I found out another issue though. Any model binding issues with OData controllers for non-nullable parameters result in the action not getting invoked. This happens as the ActionInvoker fails if a required parameter is not found. It would help if we could catch that model binding error. To help isolate it, can you change your controller code to this and run and share the error message from the client, ``` public class MyTypesController : EntitySetController<MyType, long?> { protected override MyType GetEntityByKey(long? key) { if (!ModelState.IsValid) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } return new MyType { Key = key.Value }; } } ``` Thanks a lot for helping us with the repro.
Run:
http://localhost/MyTypes(2886753098675309)
Result:
{
"odata.error": {
"code": "",
"message": {
"lang": "en-US",
"value": "The request is invalid."
},
"innererror": {
"message": "The parameters dictionary contains a null entry for parameter 'key' of non-nullable type 'System.Int64' for method 'System.Net.Http.HttpResponseMessage Get(Int64)' in 'System.Web.Http.OData.EntitySetController`2[OdataProblemDemo.Controllers.MyType,System.Int64]'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.",
"type": "",
"stacktrace": ""
}
}
}
And yet it works for an Int32
type definition:
public class MyType
{
public long Key { get; set; }
}
Controller (SHouldn't need decorating with [FromODataUri], but makes no difference):
public class MyTypesController : EntitySetController<MyType, long>
{
protected override MyType GetEntityByKey(long key)
{
return new MyType {Key = key};
}
}
and in global.asax
ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<MyType>("MyTypes");
var model = modelBuilder.GetEdmModel();
GlobalConfiguration.Configuration.Routes.MapODataRoute(
routeName: "OData",
routePrefix: null,
model: model);
Comments: I still couldn't repro this. The URL with 'L' suffix works fine on my box. I found out another issue though. Any model binding issues with OData controllers for non-nullable parameters result in the action not getting invoked. This happens as the ActionInvoker fails if a required parameter is not found. It would help if we could catch that model binding error. To help isolate it, can you change your controller code to this and run and share the error message from the client, ``` public class MyTypesController : EntitySetController<MyType, long?> { protected override MyType GetEntityByKey(long? key) { if (!ModelState.IsValid) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } return new MyType { Key = key.Value }; } } ``` Thanks a lot for helping us with the repro.