I. WCF component
1. By viewing the official example, the paging data source needs a record total value, in order to maintain versatility, here for reference to Jillzhang's article http://www.cnblogs.com/jillzhang/archive/2008/06/29/ 1232086.html, take the generic class Pagedata he wrote and use it directly.
1 using System;
2 using System.Runtime.Serialization;
4 namespace AJAX_WCF
5 {
6 [DataContract]
7 Public Class pagedata<t>
8 {
9 [DataMember]
Ten public int Totolrecord
One {get; set;}
[DataMember]
Public T Data
{get; set;}
}
17}
2. Service-side WCF method: Getdatabypage
[OperationContract]
[WebInvoke (method = "*", Responseformat = Webmessageformat.json,uritemplate = " Getdatabypage?start={start}&limit={limit} ")]
public pagedata<t_class[]> getdatabypage (int start, int Limit)
{
Pagedata<t_class[]> _result = new pagedata<t_class[]> ();
using (dbdatacontext db = new db DataContext ())
{
Try
{
iqueryable<t_class> query = db. t_classes;
_result.totolrecord = query. Count ();
var query2 = query. by (c => c.f_rootid). ThenBy (c => c.f_orders). Select (c => new {f_id = c.f_id, F_classname = c.f_classname, F_parentid =
C.f_parentid, f_orders = C.f_orders, F_R Eadme = C.f_readme}). Skip (Start). Take (limit);
_result.data = db. Executequery<t_class> (Query2, True). Toarray<t_class> ();
}
Catch {}
db. Connection.close ();
}
Return _result
}
Here's a little tip, which is also learned from Jillzhang, the class that was previously dragged out of the LINQ to SQL (DBML) Designer, the default generated code is not serializable, and we can only add [DataContract] and [DataMember] manually,
In fact, the system can be generated automatically by setting the "serialization mode" to "one-way" in the DBML property bar, as shown in the following figure: