By-page and by-page sorting, using skip and Take, and using linqskip

Source: Internet
Author: User

By-page and by-page sorting, using skip and Take, and using linqskip

Dbconn. bidRecord. orderBy (p => p. bid_id ). toList <BidRecord> (). orderBy (p => p. bid_id ). skip (skip ). take (take ). toList <BidRecord> ();

The above is the paging sorting method.

Let's talk about what to do.

Dbconn is the Modle object

BidRecord is an entity

P => p. bid_id is the sorting condition.

OrderBy is sorting (followed by conditions), and then you need to query all the data. In all the data, you need to query the data that you want to pagination. The skip address is the number of data records before the paging, that is, the total data before the current page data (skip the specified number of elements in the sequence and return the remaining elements .) PageSize * (pageIndex-1), Take is how much data is returned, that is, pageSize!

2. About the sorting of Linq:

In linq, orderby is in ascending order (A-> Z) by default. You can add descending to specify it as descending order (Z->)

Order by n descending

3. error message: the specified type of member "Date" is not supported by LINQ to Entities ". Only initial value settings, object members, and object navigation attributes are supported. Solution

  

DateTime date=DateTime.Parse(transDate);                    data = data.Where(p => EntityFunctions.DiffDays(p.TranDate,date)==0);

4. There are no methods in linq

5. datatable group statistics using groupby [2]

If you want to use group by, you can use linq, which is the content of C #3.0. Here is an example.
Static void Main (string [] args) {DataTable dt = new DataTable (); dt. columns. add ("A"); dt. columns. add ("B"); dt. columns. add ("C"); dt. rows. add ("a1", "b1", "c1"); dt. rows. add ("a1", "b2", "c2"); dt. rows. add ("a2", "b3", "c3"); dt. rows. add ("a3", "b4", "c4"); dt. rows. add ("a1", "b5", "c5"); dt. rows. add ("a2", "b6", "c6"); IEnumerable <IGrouping <string, DataRow> result = dt. rows. cast <DataRow> (). groupBy <DataRow, string> (dr => dr ["A"]. toString (); // grouping by A foreach (IGrouping <string, DataRow> ig in result) {Console. writeLine ("when A =" + ig. key + ":"); Console. writeLine ("". padRight (10) + "B ". padRight (10) + "C ". padRight (10); Console. writeLine ("==== ". padRight (10) + "==== ". padRight (10) + "==== ". padRight (10); foreach (var dr in ig) Console. writeLine (dr ["A"]. toString (). padRight (10) + dr ["B"]. toString (). padRight (10) + dr ["C"]. toString (). padRight (10);} Console. read ();}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.