c# - 在 OData 中匹配大小写属性时出现 AmbiguousMatchException

标签 c# odata

我有两个名称相同但大小写不同的属性 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 配置中包含标题:

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); 点我得到以下异常:

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

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

最佳答案

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

关于c# - 在 OData 中匹配大小写属性时出现 AmbiguousMatchException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57882781/

相关文章:

jquery - 通过 WCF 数据服务使用 OData 时出现 JSON 错误

c# - Visual Studio 部署项目可选桌面快捷方式

java - 如何在Android中使用ODATA(SMP 9.0及以上)的DateTime

linq - Web API、OData、EF5、联合 : The 'Distinct' operation cannot be applied to the collection ResultType of the specified argument

C# - 将实现接口(interface)的对象添加到字典

ado.net - ADO.NET数据服务中的自定义逻辑和代理类

asp.net - 如何将身份验证 header (基本)从 .NetClient 传递到 OData 服务

c# - 如何解析我的 Bot Framework MessagesController 中的当前对话框堆栈?

c# - 如何在 C# 中比较字符串和字符串数组?

c# - 一对零或一的关系 : Cannot insert explicit value for identity column in table when IDENTITY_INSERT is OFF