我的数据层不公开 IQueryable。我仍然希望能够对数据进行排序。我的 API 具有这样的功能,但我需要确定需要排序的内容。假设我配置了模型,例如:
ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<Airline>("Airlines");
modelBuilder.EntitySet<FlightLeg>("Legs");
现在在 Controller 中,我可以获取 OdataQueryOptions 并找出请求的 edm 模型类型/属性排序。我需要完成的是获取用于配置的 CLR 类型中的属性的 PropertyInfo,例如航空公司.PlaneModel。
我努力通过 API 获取元数据,但没有成功。请帮忙。
最佳答案
在 Controller 中尝试以下代码片段:
//using Microsoft.Data.Edm
IEdmModel edmModel = Request.ODataProperties().Model;
ClrTypeAnnotation annotation = edmModel.GetAnnotationValue<ClrTypeAnnotation>(edmSchemaType);
if (annotation != null)
{
return annotation.ClrType;
}
关于c# - 如何查找 OData edm 模型类型到 clr 类型的映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24149106/