我有两个名称相同但大小写不同的属性 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 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/