c# - 在 OData 中匹配大小写属性时出现 AmbiguousMatchException
问题描述
我有两个名称相同但大小写不同的属性,Title
并且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; }
}
我在 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 控制器的操作:
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:“找到不明确的匹配项。”
我想使用 $select 获取 Title 和 TITLE 属性。有谁知道如何解决这个问题?
解决方案
这是 OData 的问题。此问题将在 7.3 版本中修复。这是拉取请求: https ://github.com/OData/WebApi/pull/1907
推荐阅读
- php - 只是寻找一个xml标签并使用php显示在页面上
- gradle - 如何定义 settings.gradle.kts 和 build.gradle.kts 中可用的 kotlin dsl gradle 属性?
- cloud-foundry - 在空间中的所有应用程序之间启用容器到容器网络
- python - Python:如何在 netCDF4 中使用 MFdataset
- objective-c - NSOutlineView 拖放(在项目旁边)不适用于复杂项目
- python - 如何使用 OpenCV 中的 Tkinter 显示图像
- laravel - Laravel 5.6 - 404 虽然定义了路由
- c - 将数字分配给C中的char变量?
- javascript - Javascript/Angular Basics - 从范围中读取一个简单的值
- javascript - 使用 jQuery 的类和值不为空的所有选择列表选项