Skip to content

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

Open
MolallaComm opened this issue Feb 27, 2025 · 4 comments
Open

recommended spatial solution causes ODataActionParams to be null #1428

MolallaComm opened this issue Feb 27, 2025 · 4 comments
Assignees
Labels
bug Something isn't working followup

Comments

@MolallaComm
Copy link
Contributor

MolallaComm commented Feb 27, 2025

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:

            var srvaddstep1 = builder.EntityType<ServiceDTO>().Collection.Action("AddStep1");
            srvaddstep1.Parameter<AccountDTO>("Account");
            srvaddstep1.Parameter<LocationDTO>("Location");

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

@MolallaComm MolallaComm added the bug Something isn't working label Feb 27, 2025
@gathogojr gathogojr self-assigned this Mar 4, 2025
@gathogojr
Copy link
Contributor

Thank you @MolallaComm for reporting this issue. Could you try this:

srvaddstep1.EntityParameter<AccountDTO>("Account");

@gathogojr
Copy link
Contributor

Hello @MolallaComm. Did you try the suggestion above?

@MolallaComm
Copy link
Contributor Author

MolallaComm commented Mar 12, 2025 via email

@gathogojr
Copy link
Contributor

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 MapRoute that accepts two entity parameters - FromCustomer to ToCustomer. The Customer entity contains a GeographyPoint property named Location.

I run the sample OData service and POSTed the following JSON payload to the MapRoute Edm action

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 Location property is deserialized successfully:

Image

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working followup
Projects
None yet
Development

No branches or pull requests

2 participants