Questions tagged [asp.net-web-api-odata]

ASP.NET 4.x Implementation of OData Services that supports both v3-v4 of the OData Protocol. DO NOT use this tag for [asp.net-core] related questions! Use this tag if your question directly relates to the ASP.NET server-side implementation of OData services, but also include the version specific tag [odata-v3] or [odata-v4]. Only include the non-specific [odata] tag if the question has broader client-side implications.

The ASP.NET Web API OData package offers support for the OData protocol in ASP.NET Web API.

OData is a standard protocol for creating and consuming data. The purpose of OData is to provide a protocol that is based on Representational State Transfer (REST) for create, read, update, and delete (CRUD) operations. OData applies web technologies such as HTTP and JavaScript Object Notation (JSON) to provide unified convention based access to information from various programs. OData provides the following benefits:

  • It lets developers interact with data by using RESTful web services.
  • It provides a simple and uniform way to share data in a discoverable manner.
  • It enables broad integration across products.
  • It enables integration by using the HTTP protocol stack.

Two key defining features of OData over traditional RESTful APIs are the URL conventions that make it possible to compose queries that request only the specific fields and navigation links from resources that are needed on the client as well as the ability to partially update resources using the PATCH HTTP verb.

  • Together these features allow individual clients to reduce the data sent across the wire without needing changes in the API or data schema to support this.

ASP.NET Web API supports both Version 3 and Version 4 of the OData protocol.
Learn more about ASP.NET Web API OData on MSDN

The code from this package to implement this protocol makes heavy use of Language Integrated Query (LINQ) expressions to support deferred execution of client requests, in a sense the ODataLib translates a specific set of URL queries into LINQ queries.

While not required, the ASP.NET implementation has extensive support for using Entity-Framework to access the data layer, reducing the code necessary to expose EF data schemas as OData resources. For this reason Posts on SO related to this tag will often include EF references and concepts.

You can also find more information on:

134 questions
3
votes
1 answer

How can I update entity with its children? Patch method doesn't work

I must update my entity with its children list as shown here: public class Entity1 { int Id{get;set;} ObservableCollection ChildrenList {get;set;} string Name{get;set;} } public class Child1 { string Nome{get;set;} …
axa82
  • 33
  • 1
  • 6
3
votes
1 answer

Translate OData queries to SQL

I'm in an ODataController and I have an ODataQueryOptions (and all the rest of it). I know that the source of the data is a table in SQL Server. However, my EF model (that was used by the WEB API framework to route the HTTP request to my controller)…
Richard Barraclough
  • 2,625
  • 3
  • 36
  • 54
3
votes
1 answer

Cannot serialize navigation properties correctly while performing Web API Patch operation from Kendo Grid

I'm currently using Web API v2 with OData v3 linked up to a Kendo Grid. I'm having problems getting the grid to serialize a model correctly to the PatchEntityAsync method on the AsyncEntitySetController class. The Delta
3
votes
3 answers

Can I change the ODataQueryOptions used for my ODataController's request?

Update vote here on User Voice to get the ambiguity addressed. I've written a OData WebAPI controller inherting from ODataController. public class ManyColumnsController : ODataController { [Queryable( AllowedOrderByProperties =…
Jodrell
  • 34,946
  • 5
  • 87
  • 124
3
votes
2 answers

Changing serialization of Geography in JSON.NET + WebApi2/OData

I have a simple ADO.NET Entity Model which I'm exposing using OData. One of the fields in the entity model is a Geography type (geography in SQL Server). I can query the data just fine, and I get the following serialized format for the geography…
2
votes
0 answers

OData Webapi v6.0.0 $orderBy on keys with same name fails

I have OData Webapi controllers with the following model: (all the code is also available in this github repo: https://github.com/Malyngo/ODataWebapiTest) public class Customer { public int Id { get; set; } public string Name { get; set; } …
Malyngo
  • 863
  • 7
  • 18
2
votes
1 answer

OData complains about missing id property when enabling camelcasing

I want to enable camel casing of my odata results. So I added EnableLowerCamelCase. But after I enabled that I get the following error message when I call: http://localhost/odata/Users The EDM instance of type '[Core.DomainModel.User…
Snæbjørn
  • 10,322
  • 14
  • 65
  • 124
2
votes
1 answer

Strongly typed ODataActionParameters possible?

Given the below OData custom action. Is it possible to get a more refactor friendly binding of the action parameters? Both magic strings has to be exactly the same: .Parameter("Rating") and (int)parameters["Rating"]. Which is bound to break at…
Snæbjørn
  • 10,322
  • 14
  • 65
  • 124
2
votes
1 answer

How to PATCH an entity with a composite primary key?

I have an entity with a composite primary key, and I can retrieve a single instance of it using: GET https://example.com/service/Contacts(Foo=3,Bar=18) How can I update an instance of it? I tried a PATCH using the same address: PATCH…
kiewic
  • 15,852
  • 13
  • 78
  • 101
2
votes
1 answer

Configure OData property to have type Date instead of DateTime

I'm following this "guide" on how to expose Date (not DateTime) in your ODataController However I don't quite get how I should implement the .AsDate() extension method public static class PrimitivePropertyConfigurationExtensions { public static…
Snæbjørn
  • 10,322
  • 14
  • 65
  • 124
2
votes
1 answer

One to Zero or to One relationship with WebAPI OData v4

I'm using Entity Framework 4.3 and doing code first. I have two tables that are in a 1 to 0 or 1 relationship like such... class User { [key] public int UserID {get; set;} // other props } class UserStats { [key] public int…
2
votes
1 answer

get count from oData enabled web api Get function

i have an oData enabled classic REST web api controller with a Get function like [EnableQuery()] public IQueryable Get() { return _storeCommandService.GetAllStoreCommands().AsQueryable(); } i need to understand…
2
votes
3 answers

Why is there time difference between client and server on localhost

Application is running on localhost. Server is one hour earlier than client! Client sends time : Sat Apr 25 2015 00:00:00 GMT-0400 (Eastern Daylight Time) Request is sent: dateOfArrival: "2015-04-25T04:00:00.000Z" Server receives time:…
asdf_enel_hak
  • 7,474
  • 5
  • 42
  • 84
2
votes
1 answer

APN.NET WebAPI OData controller - post parameters binding

I have a problem with post requests to OData controller when the json data contains more properties than required by Post method defined in OData controller. So called over-posting is supposed to be allowed for MVC controllers, but it seems that…
bartosz
  • 21
  • 2
2
votes
0 answers

Getting an exception when using Contained navigation properties in OData

I am getting an exception while doing some testing with an OData service that makes use of containment. I'm running Web Api 2.2 / Web Api OData 5.3 / OData Lib 6.8 and using EF 6 to work with SQL Server on the back end. Here are my data…
bjohnson
  • 75
  • 5
1 2
3
8 9