Skip to content

[Select] and [Filter] are case-sensitive when getting EDM model properties' select configuration #1515

@anthony-hernandez-aas

Description

@anthony-hernandez-aas

Assemblies affected

ASP.NET Core OData 9.x

Describe the bug

Using [Select] and/or [Filter] attributes on a model do not work as intended for standard C# class/models. When annotating a property, the underling EDM model's name for that property (IEdmProperty) is lower-case while the ModelBoundQuerySettings.SelectConfigurations keys are upper-case. The TryGetValue call in EdmHelpers.cs: is failing to appropriately find the select property (in IsNotSelectable()):

SelectExpandType enable;
if (querySettings.SelectConfigurations.TryGetValue(edmProperty.Name, out enable))
{
  return enable == SelectExpandType.Disabled;
}
else
{
  return querySettings.DefaultSelectType == SelectExpandType.Disabled;
}

Reproduce steps

NOTE: It isn't clear if adding OData versioning is relevant to reproducing this problem.

  • Enable query features in Program.cs,
  • Enable OData versioning with AddRouteComponents,
  • Basic IModelConfiguration for model configuration
  • Annotate your model with the [Select] and/or [Filter] attribute, disabling specific properties
  • Set [EnableQuery] on your controller

Data Model

Model:

[Select, Filter]
public class Order
{
  public int Id { get; set; }

  [Select(SelectType = SelectExpandType.Disabled)]
  [Filter(Disabled = true)]
  public int? OwnerId { get; set; }

  public int? ContractId { get; set; }
  public int? AccountId { get; set; }
  public DateTime? EffectiveDate { get; set; }
  public DateTime? EndDate { get; set; }
}

EDM Configuration:

public class OrderModelConfig : IModelConfiguration
{  
  public void Apply(ODataModelBuilder builder, ApiVersion apiVersion, string? routePrefix)
  {
    builder.EntitySet<Order>("Orders");
  }
}

Expected behavior

$select and $filter should be enabled for all fields except the OwnerId property, e.g., validation should fail for $select=ownerId or $filter=ownerId eq 1. Using upper-casing in the clasues does not fix the problem, e.g.: $select=OwnerId or $filter=OwnerId eq 1.

Additional context

Controller:

[EnableQuery]
[HttpGet, Route("Orders")]
public IQueryable<Order> Get()
{
  return _dbContext.Orders;
}

Program startup:

builder.Services
        .AddOData(options =>
        {
          options.EnableQueryFeatures(100);
        });

builder.Services.AddApiVersioning().AddOData(options =>
  options.AddRouteComponents((services) =>
  {
    services.AddSingleton<ODataUriResolver>(sp =>
            new UnqualifiedODataUriResolver
            {
              EnableCaseInsensitive = true // https://github.com/OData/AspNetCoreOData/issues/1312#issuecomment-2360244163
            });
  }));

NOTE: Adding or removing the UnqualifiedODataUriResolver above does not affect the outcome. The underlying code in EdmHelper.cs doesn't seem to care about case-sensitivity anyway.

Metadata

Metadata

Assignees

Labels

P3bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions