我有两个名称相同且大小写不同的属性TitleTITLE:

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; }
}

我在OData配置中包含Title:
ODataModelBuilder builder = new ODataConventionModelBuilder();
        builder.EntitySet<Product>("Products");
        builder.EntityType<Product>().Property(a => a.Title);
        config.MapODataServiceRoute(
        routeName: "ODataRoute",
        routePrefix: null,
        model: builder.GetEdmModel());

这是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);
  }

当我发送https://localhost:44326/Products?$select=Id,TITLE请求时,在queryOptions.ApplyTo(products);点上,我得到以下异常:



我想使用$ select获得Title和TITLE属性。有谁知道如何解决这个问题?

最佳答案

这是OData的问题。此问题将在7.3版本中修复。这是请求请求:
https://github.com/OData/WebApi/pull/1907

10-02 02:01
查看更多