我有两个名称相同,大小写不同的属性,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配置中包含Title:
ODataModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet("Products"); builder.EntityType ().Property(a => a.Title); config.MapODataServiceRoute( routeName: "ODataRoute", routePrefix: null, model: builder.GetEdmModel());
这是OData控制器的操作:
public IHttpActionResult Get(ODataQueryOptionsqueryOptions, CancellationToken cancellationToken) { Context = GetContext(); var products = Context.GetEntities (); var result = queryOptions.ApplyTo(products); return Ok(result); }
当我发送https://localhost:44326/Products?$select=Id,TITLE
请求时,queryOptions.ApplyTo(products);
我会收到以下异常:
System.Reflection.AmbiguousMatchException:'找到了模糊的匹配项。
我想使用$ select获得Title和TITLE属性。有谁知道如何解决这个问题?