Three ways: LINQ, LAMBDA, SQL syntax
1. Simple LINQ Syntax
1 var ss = from R in Db. Am_recproscheme Select R; 2 var SS1 = db. Am_recproscheme; 3 String sssql = "SELECT * from Am_recproscheme";
2. Query with where
1 var ss = from R in Db. Am_recproscheme where r.rpid > select R; 2 var SS1 = db. Am_recproscheme.where (p = p.rpid >); 3 String sssql = "SELECT * from Am_recproscheme where rpid>10";
3. Simple function calculation (count,min,max,sum)
1////gets the largest rpid//var SS = (from R in Db. Am_recproscheme//Select R). Max (p = p.rpid); Gets the smallest rpid//var ss = (from R in Db. Am_recproscheme//Select R). Min (p = p.rpid); Gets the total number of result sets//var SS = (from R in Db. Am_recproscheme//Select R). Count (); Gets the Rpid and var ss = (from R in Db. Am_recproscheme Select R). Sum (p = p.rpid); 2//var SS1 = db. Am_recproscheme.max (P=>P.RPID); var SS1 = db. Am_recproscheme.min (p = p.rpid); var SS1 = db. Am_recproscheme.count (); var SS1 = db. Am_recproscheme.sum (p = p.rpid); Response.Write (ss); 3 String sssql = "Select Max (rpid) from Am_recproscheme"; Sssql = "Select min (rpid) from Am_recproscheme"; Sssql = "Select Count (1) from Am_recproscheme "; Sssql = "Select sum (rpid) from Am_recproscheme";
4. Sort ORDER BY Desc/asc
var ss = from R in Db. Am_recproscheme where r.rpid > r.rpid Descending //reverse //by R.rpid Ascending //Positive sequence select R; Positive -order var SS1 = db. Am_recproscheme.orderby (p = p.rpid). Where (p = p.rpid > 10). ToList (); Reverse var SS2 = db. Am_recproscheme.orderbydescending (p = p.rpid). Where (p = p.rpid > 10). ToList (); String sssql = "SELECT * from Am_recproscheme where rpid>10 order by Rpid [DESC|ASC]";
5.top (1)
If the last one can be sorted in flashbacks, then the value var ss = (from R in DB). Am_recproscheme Select R). FirstOrDefault (); () LINQ to EF does not seem to support last () var SS1 = db. Am_recproscheme.firstordefault (); var SS1 = db. Am_recproscheme.first (); String sssql = "SELECT Top (1) * from Am_recproscheme";
6. Skip the previous number of data to take the remaining data
1 var ss = (from R in Db. Am_recproscheme r.rpid Descending Select R). Skip (10); Skip the first 10 data and fetch all the data after 10 //2 var ss1 = db. Am_recproscheme.orderbydescending (p = p.rpid). Skip (10). ToList (); 3 String sssql = "SELECT * from" ( select Row_number () over (order by rpid Desc) as RowNum, * from [Am_recproscheme] ) as T where rownum>10 ";
7. Paging Data Query
1 var ss = (from R in Db. Am_recproscheme where r.rpid > r.rpid descending Select R). Skip (10). Take (10); Takes 11th to 20th data//2 take (10): Data is obtained from the beginning, obtaining a specified number (10) of continuous data var SS1 = db. Am_recproscheme.orderbydescending (p = p.rpid). Where (p = p.rpid > 10). Skip (10). Take (10). ToList (); 3 String sssql = "SELECT * from" ( select Row_number () over (order by rpid Desc) as RowNum, * from [Am_recproscheme] ) as T where rownum>10 and rownum<=20 ";
8. Include, like '% '
1 var ss = from R in Db. Am_recproscheme where R.sortstext.contains ("Zhang") select R; 2 var SS1 = db. Am_recproscheme.where (p = p.sortstext.contains ("Zhang")). ToList (); 3 String sssql = "SELECT * from Am_recproscheme where sortstext like '% Zhang% '";
9. GROUP BY
1 var ss = from R in Db. Am_recproscheme r.rpid Descending Group R by R.rectype into N Select New {N.key,//This Key is rectype rpid = N. Sum (r = r.rpid),//group rpid and maxrpid = N.max (r = r.rpid),//group Max Rpid Minrpid = N.min (r = r.rpid),//Minimum rpid} in the group; foreach (Var t in ss) {Response.Write (T.key + "--" + T.rpid + "--" + T.maxrpid + "--" + T.MINRP ID); }//2 var ss1 = from R in Db. Am_recproscheme r.rpid Descending Group R by R.rectype into N Select N; foreach (Var t in Ss1) {Response.Write (T.key + "--" + t.min (p = = p.rpid)); }//3 var ss2 = db. Am_recproScheme.groupby (p = p.rectype); foreach (Var t in Ss2) {Response.Write (T.key + "--" + t.min (p = = p.rpid)); }//4 String sssql = "Select Rectype,min (rpid), Max (rpid), sum (rpid) from Am_recproscheme GROUP BY rec Type ";
10. Connection Query
1 var ss = from R in Db. Am_recproscheme join W in DB. Am_test_result on r.rpid equals w.rsid r.rpid descending select R; 2 var SS1 = db. Am_recproscheme.join (db. Am_test_result, p = p.rpid, r = R.rsid, (p, r) = p). OrderByDescending (p = p.rpid). ToList (); 3 String sssql = "Select r.* from [Am_recproscheme] as R inner join [dbo].[ Am_test_result] as T on r.[rpid] = T.[rsid] ORDER by r.[rpid] desc ";
In of 11.sql
1 var ss = from P in db. Am_recproscheme where (new int?[] {24, 25,26}). Contains (p.rpid) select P; foreach (Var p in ss) { Response.Write (p.sorts); } 2 String st = "SELECT * from Am_recproscheme where rpid in (24,25,26)";
LINQ syntax Verbose (Three ways: LINQ, LAMBDA, SQL Syntax)