OData版本:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.OData" version="5.9.1" targetFramework="net45" />
<package id="Microsoft.OData.Core" version="6.15.0" targetFramework="net45" />
<package id="Microsoft.OData.Edm" version="6.15.0" targetFramework="net45" />
<package id="Microsoft.Spatial" version="6.15.0" targetFramework="net45" />
</packages>
枚举颜色:
public enum Color
{
Red = 1,
Green = 2,
Blue = 3
}
车辆类:
public class Vehicle
{
public Guid VehicleId { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public Color? Color { get; set; }
}
Web API端点:
[HttpGet]
[Route("vehicles")]
public IHttpActionResult GetVehicles(ODataQueryOptions<Vehicle> options)
{
var query = dbContext.Vehicle.Select(x => new Vehicle
{
VehicleId = x.VehicleId, // guid type for x.VehicleId
Color = (Color?)x.ColorId // nullable int type for x.ColorId
});
var odataQuery = options.ApplyTo(query) as IQueryable<object>;
return Ok(odataQuery.AsEnumerable<Vehicle>());
}
情景1:
尝试http://localhost:1000/vehicles?$ apply = groupby((vehicleId))并且它正在运作。
情景2:
但是使用http://localhost:1000/vehicles?$ apply = groupby((color)),这将抛出错误消息(&#34; exceptionMessage&#34;:&#34;参数类型不匹配&#34;)。
答案 0 :(得分:1)
以下是odata.org google group的答案。
从规范角度来看,枚举类型是原始类型,所以 它们可以在groupby中使用。
但这并不能保证您的首选工具集已经存在 支持这一点。