我的数据层没有公开IQueryable。我仍然希望能够对数据进行排序。我的API具有这种功能,但是我需要确定需要排序的内容。假设我配置了模型,例如:
ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<Airline>("Airlines");
modelBuilder.EntitySet<FlightLeg>("Legs");
现在,在控制器中,我可以获取OdataQueryOptions并找出请求的edm模型类型/属性排序。我需要完成的工作是获取用于配置的CLR类型的属性的PropertyInfo,例如Airline.PlaneModel。
我很难通过API获得该元数据,但没有成功。请帮忙。
最佳答案
在控制器中尝试以下代码片段:
//using Microsoft.Data.Edm
IEdmModel edmModel = Request.ODataProperties().Model;
ClrTypeAnnotation annotation = edmModel.GetAnnotationValue<ClrTypeAnnotation>(edmSchemaType);
if (annotation != null)
{
return annotation.ClrType;
}