Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

asp.net

odata

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?

like image 350
Sunkist Avatar asked Jan 29 '26 02:01

Sunkist


2 Answers

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().

like image 138
Stefan Balan Avatar answered Jan 31 '26 21:01

Stefan Balan


In ASP.NET Core 3.1, package Microsoft.AspNetCore.OData, most values under Request.ODataProperties() are now under Request.ODataFeature().

like image 31
Simmetric Avatar answered Jan 31 '26 19:01

Simmetric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!