Unable to configure spatial properties using ODataModelBuilder
Nobody has claimed this yet.
- 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:
Additional Details
- The
Propertymethod 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 becauseTis constrained tostruct, and spatial types likeGeographyPointdo 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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