简体   繁体   中英

ODataProperties (System.Web.OData.Extensions - OData v4) Missing ''Model' Property

I am trying to create an instance of ODataQueryContext which requires an EdmModel reference. I am attempting to get the Model from ODataProperties() which is a method call off of the HttpRequestMessage object.

var orderBy = new OrderByQueryOption("ColumnName desc", new ODataQueryContext(Request.ODataProperties().Model, typeof(MyType)));

It seems that if I use the namespace using System.Web.Http.OData.Extensions; as opposed to using System.Web.OData.Extensions; the Model property is available from ODataProperties() . However, I am using the newer version (OData v4) namespaces, for other references in my program.

After doing some research I determined that with OData v4, they moved everything from Web.Http.OData.* namespaces, to Web.OData.* namespaces. I am assuming that I need to be consistent in using either the new or old namespaces, and I was not successful attempting to mix them.

Does anyone know how to get the Model property from ODataProperties() without using the older Web.Http.OData namespaces?

To anyone still having trouble with this (I ended-up here from a MS OData tutorial) request.ODataProperties().Model has changed to request.GetModel() ( HttpRequestMessageExtensions in namespace Microsoft.AspNet.OData.Extensions in assembly Microsoft.AspNet.OData). Also request.ODataProperties().PathHandler has changed to request.GetPathHandler() .

在 ASP.NET Core 3.1 包 Microsoft.AspNetCore.OData 中, Request.ODataProperties()下的大多数值现在位于Request.ODataFeature()

ODataProperties().Model 来自 github 上的 OData

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