OData V4 modify $filter on server side

Remove [EnableQuery] attribute, your scenario should work, because after using this attribute, OData/WebApi will apply your original query option after you return data in controller, if you already apply in your controller method, then you shouldn’t use that attribute. But if your query option contains $select, those code are not working because the result’s type … Read more

Net Core: Using OData in Onion Architecture, Convert Query Parameters Into Linq

It’s been ages since I wrote this function, but the links might help. GetAll() just returns an IEnumerable. [Route(“”), HttpGet] public IHttpActionResult Get(ODataQueryOptions<Language> queryOptions) { Log.Info($”{nameof(Get)} (ODataQueryOptions)”); //OData directly with normal WebAPI //https://blogs.msdn.microsoft.com/webdev/2013/02/25/translating-odata-queries-to-hql/ //https://stackoverflow.com/questions/10781309/asp-net-mvc-4-webapi-manually-handle-odata-queries //https://blogs.msdn.microsoft.com/odatateam/2014/07/04/tutorial-sample-using-odatauriparser-for-odata-v4/ //OData without entity framework, but full-on odata controller //http://www.odata.org/blog/how-to-use-web-api-odata-to-build-an-odata-v4-service-without-entity-framework/ //OData tips and tricks //https://blogs.msdn.microsoft.com/davidhardin/2014/12/17/web-api-odata-v4-lessons-learned/ return Ok(queryOptions.ApplyTo(_repository.GetAll().AsQueryable())); }

How to make use of navigation property?

Navigation properties are, as the name suggests, properties with which you can navigate to related entity types. The UI5 framework supports this feature too so that app developers don’t have to extract URLs by hand. In fact, you won’t even need to call read. Let’s take this entity data model for example: CustomerSet NavigationProperty: “ToOrders” … Read more

Adding a custom query backed Navigation Property to ODataConventionModelBuilder

You have to call “AddNavigationTarget” on the EntitySet. Assume that your namespace is “MyNamespace”, then add the following code to your WebApiConfig.cs. In this way, retrieving the data with “Get: odata/Cars(1)/Parts” will work. var cars = (EdmEntitySet)edmModel.EntityContainers().Single().FindEntitySet(“Cars”); var parts = (EdmEntitySet)edmModel.EntityContainers().Single().FindEntitySet(“Parts”); var carType = (EdmEntityType)edmModel.FindDeclaredType(“MyNamespace.Car”); var partType = (EdmEntityType)edmModel.FindDeclaredType(“MyNamespace.Part”); var partsProperty = new EdmNavigationPropertyInfo(); partsProperty.TargetMultiplicity … Read more

How to in-code supply the password to a connection string in an ADO.Net Entity Data Model

When you create your context, you can set a connection string. To build this connection string, you can parse the connection string without the password with an EntityConnectionStringBuilder and then parse the inner connection string with an other ConnectionStringBuilder, depending on your browser. Then you can set the password and pass it to the constructor. … Read more

OData with ServiceStack? [closed]

Edit ServiceStack has now added Auto Query which is our approach to enabling data-driven services that avoids the pitfalls and anti-patterns promoted by OData. Will ServiceStack support OData. No. Not directly anyway. If anyone sees any value in OData they are free to add the necessary functionality as an optional Plugin – but it will … Read more

How to get model on onInit?

You can avoid setTimeout, as mentioned in this answer, by using the v2.ODataModel API metadataLoaded instead which returns a promise. The promise is fulfilled once the service metadata is loaded successfully. onInit: async function() { const oPayerModel = this.getOwnerComponent().getModel(“SalesInvoices”); try { await oPayerModel.metadataLoaded(true); const oServiceMetadata = oPayerModel.getServiceMetadata(); // NOT .getMetadata() // … } catch (oError) … Read more

Web API and OData- Pass Multiple Parameters

You can define a function import named GetReports that has two parameters. (Note: the name of the function import can’t be the same with entity set name) Configure your EDM model as: var builder = new ODataConventionModelBuilder(); builder.EntitySet<Report>(“Reports”); var function = builder.Function(“GetReports”); function.Parameter<int>(“Id”); function.Parameter<int>(“Year”); function.ReturnsCollectionFromEntitySet<Report>(“Reports”); var model = builder.GetEdmModel(); And then write your method as: … Read more