【问题标题】:How to find mapping of OData edm model type to clr type?如何找到 OData edm 模型类型到 clr 类型的映射?
【发布时间】:2014-07-31 16:40:48
【问题描述】:

我的数据层没有公开 IQueryable。我仍然希望能够对数据进行排序。我的 API 具有这样的功能,但我需要确定需要排序的内容。假设我配置了模型,例如:

ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<Airline>("Airlines");
modelBuilder.EntitySet<FlightLeg>("Legs");

现在在控制器中,我可以获取 OdataQueryOptions 并找出请求的 edm 模型类型/属性排序。我需要完成的是获取用于配置的 CLR 类型中属性的 PropertyInfo,例如Airline.PlaneModel。

我很难通过 API 获取元数据,但没有成功。请帮忙。

【问题讨论】:

    标签: c# .net asp.net-mvc asp.net-web-api odata


    【解决方案1】:

    在控制器中试试这个代码 sn-p:

            //using Microsoft.Data.Edm
            IEdmModel edmModel = Request.ODataProperties().Model;
            ClrTypeAnnotation annotation = edmModel.GetAnnotationValue<ClrTypeAnnotation>(edmSchemaType);
            if (annotation != null)
            {
                return annotation.ClrType;
            }
    

    【讨论】:

    • 谢谢,谭。您从哪里获得这些功能的文档?
    • 这很好用,但是如果我有一个实体集合并且我需要底层类型怎么办?我在哪里可以找到这方面的一些文档?
    猜你喜欢
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    • 1970-01-01
    • 2012-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多