Search code examples
c#odata

AmbiguousMatchException while match case property in OData


I have two properties with the same name and with a different case Title and TITLE:

public class Product
{
    [Key]
    public Guid Id { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
    public string Category { get; set; }

    [NotMapped]
    public virtual string Title { get; set; }

    public string TITLE { get; set; }
}

I'm including Title in OData config:

ODataModelBuilder builder = new ODataConventionModelBuilder();
        builder.EntitySet<Product>("Products");
        builder.EntityType<Product>().Property(a => a.Title);
        config.MapODataServiceRoute(
        routeName: "ODataRoute",
        routePrefix: null,
        model: builder.GetEdmModel());

Here is action of OData controller:

  public IHttpActionResult Get(ODataQueryOptions<Product> queryOptions, CancellationToken cancellationToken)
  {
     Context = GetContext();
     var products = Context.GetEntities<Product>();
     var result = queryOptions.ApplyTo(products);
     return Ok(result);
  }

When I send https://localhost:44326/Products?$select=Id,TITLE request, in queryOptions.ApplyTo(products); point I am getting following exception:

System.Reflection.AmbiguousMatchException: 'Ambiguous match found.'

I want to get Title and TITLE property using $select. Does anyone know how to fix this problem?


Solution

  • It was an issue of OData. This issue will be fixed in 7.3 version. Here is Pull request: https://github.com/OData/WebApi/pull/1907