Advanced query of LinQ and advanced query of LinQ
Fuzzy query:
// Database + custom name = new database // example: mydbDataContext con = new mydbDataContext (); // used in fuzzy query expressions. containscon. car. where (r => r. name. contains (TextBox1.Text. trim ())). toList (); // start with query. startWithcon. car. where (r => r. name. startsWith (TextBox1.Text )). toList (); // used for end query. endWithcon. car. where (r => r. name. endsWith (TextBox1.Text )). toList ();
Maximum value, minimum value:
// Maximum // example: con. car. max (r => r. price * r. oil ). toString (); // minimum // example: con. car. min (r => r. price ). toString ();
Sum, average value:
// Sum con. car. sum (r => r. price ). toString (); // average con. car. average (r => r. price ). toString ();
Ascending and descending:
// Ascending Order: con. car. orderBy (r => r. price ). toList (); // descending order: con. car. orderByDescending (r => r. price ). toList ();
Previous Page, next page, Combined Query:
Int PageCount = 5; // number of entries displayed per page // Previous Page, PageCount_Label.Text indicates the current page number int pageNum = Convert. toInt32 (PageCount_Label.Text)-1; Repeater1.DataSource = con. car. skip (pageNum-1) * PageCount ). take (PageCount); Repeater1.DataBind (); PageCount_Label.Text = pageNum. toString (); // int pageNum = Convert. toInt32 (PageCount_Label.Text) + 1; Repeater1.DataSource = con. car. skip (pageNum-1) * PageCount ). take (PageCount); R Epeater1.DataBind (); PageCount_Label.Text = pageNum. ToString (); // click event List for Combined Query <car> list = con. car. ToList (); if (TextBox2.Text! = "") {List <car> list1 = con. car. where (r => r. name. contains (TextBox2.Text )). toList (); list = list. intersect (list1 ). toList ();} if (TextBox3.Text! = "") {List <car> list1 = con. car. where (r => r. oil = Convert. toDecimal (TextBox3.Text )). toList (); list = list. intersect (list1 ). toList ();} if (TextBox4.Text! = "") {List <car> list1 = con. car. where (r => r. powers = Convert. toInt32 (TextBox4.Text )). toList (); list = list. intersect (list1 ). toList ();} Repeater1.DataSource = list; Repeater1.DataBind ();