The OData protocol, how cow B technology,
Traditional page-writing habits, the recent project, using the ASP. NET WebAPI 2.0来 to do data interface, as for why to use WebAPI, I think as long as the OData protocol has a knowledge of friends. Just say that Webapi will think of this, if you want to have more in-depth understanding of it. You can take a brief introduction to the blog Park (Zhang Shanyu master). URL (http://www.cnblogs.com/shanyou/archive/2010/03/26/1697316.html)
Microsoft 5.5.2.0 System.Web.OData.dll, does not support $inlinecount queries, and currently I have not found a paging solution for ASP. NET WEBAPI Support OData protocol (if a friend knows it, please share it with me, Thank you very much! )
To do this, we have to do a paging query, we have to write a paging query program (FILTER), to support the OData protocol, we must use the OData support class library provided by Microsoft, because only support $filter, $orderby these operations. The pages we write ourselves will make sense if these query operations are not supported by the OData protocol. Query Shang and so on. That, like the traditional data interface, loses the true meaning of the WEBAPI support OData protocol. Anyway, I used the OData protocol some interface, I feel very convenient, extensibility is also very good. It should be said that WEBAPI will be a good service interface solution,
What do you need for paging?
Pagination contains several elements: Total number of records, number of pages per page, total pages, current page, data list. This is pretty much the 5 elements that need to be included in a paging result. In fact, for paging, the server needs to return the data. There are only two of them.
First: The total number of records. The total number of records, must be returned to the server side, and then the client can be defined by their own page, to calculate the total number of pages, the client to save their current page numbers and so on.
Second: Data list. This must be returned by the service side (not mentioned).
Well, then, let's start with the first thing, define the paging object to return the result object. Yes, as you can imagine, it's very simple, just two attributes.
/// <summary> /// define a paged data return object /// ------------------------------- /// add by hotboy 2015-5-13 11:21:49 /// </summary> public class ODataPagedResult { Internal odatapagedresult (object data, int total) { this._data = data; this._total = total; } private object _data; /// <summary> ///&nBsp Get the data object /// </summary> public object Data { get { Return this._data; } private set { this._data = value; } } private int _total; /// <summary> /// Get the total count /// </summary> public int Total { get { return this._total; } private set { this._total = value; } } }
Starting with the next article, we'll explore the ASP. NET WEBAPI specific paging implementation code for the OData protocol.
This article is from the "idiot" blog, make sure to keep this source http://hotboy.blog.51cto.com/8826994/1651240
I use ASP. Webapi to support the OData protocol for paging operations (first article)