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
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.
Describe the Bug
Currently, configuring an EDM model with spatial properties is only supported via the
ODataConventionModelBuilder. Attempting to manually configure such a model usingODataModelBuilderresults 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:
Attempt to manually configure the EDM model:
Expected Behavior
The EDM model should be configured successfully using
ODataModelBuilder, allowing spatial properties likeGeographyPointto be registered manually.Actual Behavior
An error is thrown when attempting to register the spatial property manually:
Additional Details
Propertymethod being invoked has the following signature:UntypedPropertyConfiguration Property(Expression<Func<TStructuralType, object>>)Property, such as:PrimitivePropertyConfiguration Property<T>(Expression<Func<TStructuralType, T?>>)cannot be used because
Tis constrained tostruct, and spatial types likeGeographyPointdo not satisfy this constraint.