简体   繁体   中英

How to find mapping of OData edm model type to clr type?

My data layer doesn't expose IQueryable. Still I want to be able to sort data. My API has such capability but I need to identify what needs to be sorted. Say I configured the model, eg:

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

Now in controller I'm able to get OdataQueryOptions and find out on what edm model types/properties sorting is requested. What I need to accomplish is to get PropertyInfo of the property in the CLR type that was used for configuration, eg Airline.PlaneModel.

I struggle to get that metadata through the API but without success. Please, help.

Try this code snippet in a controller:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM