OData / OData/ModelBuilder

Unable to configure spatial properties using ODataModelBuilder

Open
#56 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P4
Dominant language
C#
Stars
22
Forks
24
PR merge metrics
No merged PRs in 30d

Description

Describe the Bug

Currently, configuring an EDM model with spatial properties is only supported via the ODataConventionModelBuilder. Attempting to manually configure such a model using ODataModelBuilder results in an error, making it impossible to use the non-convention-based builder for spatial types.

Steps to Reproduce

Define a data model with a spatial property:
namespace Sample.Models
{
    public class Site
    {
        public int Id { get; set; }
        public GeographyPoint Location { get; set; }
    }
}
Attempt to manually configure the EDM model:
using Sample.Models;
using Microsoft.AspNetCore.OData;
using Microsoft.OData.ModelBuilder;

var builder = WebApplication.CreateBuilder(args);

var modelBuilder = new ODataModelBuilder();
var siteEntityType = modelBuilder.EntityType<Site>();
siteEntityType.HasKey(s => s.Id);
siteEntityType.Property(s => s.Location);

builder.Services.AddControllers().AddOData(
    options => options.EnableQueryFeatures().AddRouteComponents(
        modelBuilder.GetEdmModel()));

var app = builder.Build();

app.UseRouting();
app.MapControllers();

app.Run();

Expected Behavior

The EDM model should be configured successfully using ODataModelBuilder, allowing spatial properties like GeographyPoint to be registered manually.

Actual Behavior

An error is thrown when attempting to register the spatial property manually:

Image

Additional Details

  • The Property method being invoked has the following signature:
    UntypedPropertyConfiguration Property(Expression<Func<TStructuralType, object>>)
  • The generic overloads of Property, such as:
    PrimitivePropertyConfiguration Property<T>(Expression<Func<TStructuralType, T?>>)
    cannot be used because T is constrained to struct, and spatial types like GeographyPoint do not satisfy this constraint.
  • To support manual configuration of spatial types, it may be necessary to introduce a new overload or extend the existing API to handle these cases explicitly.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ODataModelBuilder.Property overloads and the GetEdmModel path described in the reproduction. Trace how GeographyPoint reaches the untyped property configuration and compare it with ODataConventionModelBuilder handling. Done means the manual builder accepts the spatial property and produces an EDM model without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.