Is ODATA using the Microsoft Web API architecture truly a REST architecture?

The more I study the Microsoft framework on ODATA, I tend to believe that it is not suitable for an enterprise application. The structure expects the entire database to be directly displayed as a ViewModel, even for simple operations such as paging and sorting.

We will be forced to use a static mechanism to store page numbers that are displayed to the JavaScript client.

Or do I not understand the correct implementation of Microsoft OData?

EDIT-1:

Is ODATA V4 a historical architecture? How Microsoft Templates Are Moving On. I do not see any easy migration path from Asp.Net Web API (REST) ​​for OData architecture (STATEFUL Sounds).

EDIT-2: Paging, sorting, and grouping are part of an incoming request from a client.

0
c # rest odata pagination
source share
1 answer

In short, the server-side implementation of MS Odata is not statefull and can be considered a REST architecture.

We will be forced to use a static mechanism to save page numbers displayed to the JavaScript client.

In the request, you provide the swap information. For example, if you want 10 elements of page 2, you should take the top 10 and skip the 10.

odata-url/?$count=true&$top=10&$skip=10 

As you can see, the client / caller indicates paging, the server should not monitor the status of the client.

Also, adding $count=true will return the total number of records based on the passed to the filter included in the result set (in the above example, there is no filter). This will allow the client to calculate the number of pages.


The structure expects the entire database to be directly opened as a ViewModel ...

Also not true. You can return an IQueryable<T> , where T is your type. T does not have to be an EF model. For example, returning the next from a DbContext .

 public IQueryable<SomeEntity> Get() { return dbContext.SomeEntities .Where(x => optionalPreFiltereExpression) .Select(x => new SomeDTO(){ Prop1 = x.Prop1, Collection1 = x.CollectionOfInterest, // etc }); } 

To illustrate this point, you can also return a hard list of objects, although this may be unlikely in production.

 public IQueryable<SomeEntity> Get() { return new List<SomeDTO>(){ new SomeDTO(){ Prop1 = 5, Prop2 = "Hi there" // etc}, new SomeDTO(){ Prop1 = 6, Prop2 = "Goodbye" // etc} }).AsQueryable(); } 

There are many resources for all OData options. I am not going to include everything here, otherwise I could just create a second set of documentation.

+5
source share

All Articles