-
Notifications
You must be signed in to change notification settings - Fork 170
recommended spatial solution causes ODataActionParams to be null #1428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thank you @MolallaComm for reporting this issue. Could you try this: srvaddstep1.EntityParameter<AccountDTO>("Account"); |
Hello @MolallaComm. Did you try the suggestion above? |
Yes – I tried using EntityParameter just now and it didn’t help – ODataActionParameters is always null in my controller when any of the parameters contain a spatial property unfortunately.
FWIW, I did hack my client code to just remove that spatial property from the JSON before it sends it to the controller and it works then, but that isn’t really a solution.
|
Hi @MolallaComm. Unfortunately I'm unable to repro the issue you reported in spite of my best efforts. Payload for Edm actions seem to get serialized successfully even when they contain spatial properties. Here's the code from my attempt to repro the issue: Data model: namespace AspNetCoreOData1428Repro.Models
{
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public GeographyPoint Location { get; set; }
}
} Edm model definition and service configuration: var builder = WebApplication.CreateBuilder(args);
var modelBuilder = new ODataConventionModelBuilder();
var customerEntityTypeConfiguration = modelBuilder.EntitySet<Customer>("Customers").EntityType;
var mapRouteActionConfiguration = customerEntityTypeConfiguration.Collection.Action("MapRoute");
mapRouteActionConfiguration.EntityParameter<Customer>("FromCustomer");
mapRouteActionConfiguration.EntityParameter<Customer>("ToCustomer");
builder.Services.AddControllers().AddOData(
options => options.EnableQueryFeatures().AddRouteComponents(
modelBuilder.GetEdmModel()));
var app = builder.Build();
app.UseRouting();
app.UseODataRouteDebug();
app.MapControllers();
app.Run(); Controller: namespace AspNetCoreOData1428Repro.Controllers
{
public class CustomersController : ODataController
{
[HttpPost]
public ActionResult MapRoute(ODataActionParameters parameters)
{
return Ok();
}
}
} The sample code above define an Edm action I run the sample OData service and POSTed the following JSON payload to the Request endpoint: POST http://localhost:5018/Customers/MapRoute Request body: {
"FromCustomer": {
"Id": 1,
"Name": "Microsoft",
"Location": {
"type": "Point",
"coordinates": [
-122.1366,
47.6425
],
"crs": {
"type": "name",
"properties": {
"name": "EPSG:4326"
}
}
}
},
"ToCustomer": {
"Id": 2,
"Name": "Google",
"Location": {
"type": "Point",
"coordinates": [
-122.0841,
37.4220
],
"crs": {
"type": "name",
"properties": {
"name": "EPSG:4326"
}
}
}
}
} By placing a breaking point on the executable endpoint mapped to the Edm action, I observed that the I urge you to share a repro that we can help us identify the issue you're experiencing. If on the other hand, the issue is related to code you adopted from the blog post you referred to, I'd urge you to leave a comment on that blog post explaining what scenario doesn't seem to work. Details steps to reproduce would help there as well. The poster of the blog would be best placed to advise. If its not an issue with this library in particular, we'll go ahead and close the issue. |
I added a Point property to my entity following this guide:
https://devblogs.microsoft.com/odata/customizing-filter-for-spatial-data-in-asp-net-core-odata-8/
It seems a bit convoluted, but worked fine, in that I can query my "LocationDTO" entity and run spatial filters/orderbys as expected. However, now when I try to use that entity as a parameter for actions, it doesn't work anymore - for instance:
With the spatial column added, the ODataActionParameters in my controller function is always null - despite the fact I can see that the client is sending what looks like the proper JSON. If I comment out the spatial stuff in LocationDTO, everything goes back to working as expected (i.e. ODataActionParameters in my controller is no longer null).
Using latest/greatest odata on .netcore 8
The text was updated successfully, but these errors were encountered: