In short the MS Odata server side implementation is not statefull and it can be considered a REST architecture.
We would be forced to use stasteful mechanism to persist page numbers rendered to the JavaScript client
You provide paging information in the request. For example, if you wanted 10 items of page 2 you would take the top 10 and skip 10.
odata-url/?$count=true&$top=10&$skip=10
As you can see the client/caller specifies the paging, there is no need for the server to track state of the client.
Also adding $count=true
will return the total number of records based on the passed in 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 there are.
The framework expects all the database to be directly exposed as 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 following from a DbContext
is acceptable.
public IQueryable<SomeEntity> Get() {
return dbContext.SomeEntities
.Where(x => optionalPreFiltereExpression)
.Select(x => new SomeDTO(){
Prop1 = x.Prop1,
Collection1 = x.CollectionOfInterest,
// etc
});
}
To further illustrate that point you could also return a hard coded list of objects, although this might not be very likely 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 on all the options for OData. I am not going to include everything here, otherwise I might as well just be creating a 2nd set of documentation.