ServiceStack.OrmLiteノート10-group havingページングorderbyなど

1937 ワード

group havingページング等
var ev = OrmLiteConfig.DialectProvider.SqlExpression ();
groupの使用はsqlと同じで、groupパケットのフィールドはselectにあることに注意してください
ev.Select(c => new { c.Birthday, c.Active }).Where(rn => rn.Birthday >= new DateTime(year, 1, 1) && rn.Birthday <= lastDay).GroupBy(rn => new { rn.Birthday,rn.Active});
havingの使用
ev.Select(c => new { c.Birthday, c.Active }).Where(rn => rn.Birthday >= new DateTime(year, 1, 1) && rn.Birthday <= lastDay).GroupBy(rn => new { rn.Birthday, rn.Active }).Having(x=>Sql.Max(x.Rate)>5);
orderbyソート1リットル1降下先降下後上昇ordered by Rate Descending and Name Ascending ev.Where().OrderBy(rn=>new{at=Sql.Desc(rn.Rate)、rn.Name})もこのOrderByDescendingを使用できます
Limitのページングはskipでtake evですLimit(5); デフォルトはtake、すなわちtop 5 evである.Limit(0, 4);//first page, page size=4; ev.Limit(4, 4);//second page ev.Limit().OrderBy();//clear limit, clear orde
 ToCountStatement   
  var expr = db.From<LetterFrequency>() .Join<LetterFrequency, LetterStat>() .Where<LetterStat>(x => x.Id > 0);

var rscount= expr.ToCountStatement();//expr式の結果を取得した合計数
 ev.SelectDistinct(r => r.City);
 ev.Select(r => Sql.As(Sql.Max(r.Birthday), "Birthday")); //   Birthday
 var r2 = db.Scalar<Author, DateTime>(e => Sql.Max(e.Birthday));Author  DateTime  

LeftJoinの結合
db.Column < string > ( db.From < TableA > () .LeftJoin < TableB >((a, b) => a.Id == b.Id) .Where < TableB > (b => b.Id == null) .Select(a => a.Name));
Join
db.From < TableA > () .Join < TableB > () .OrderBy(x => x.Id);
CrossJoin
db.From < CrossJoinTableA > () .CrossJoin < CrossJoinTableB >() .OrderBy < CrossJoinTableA >(x => x.Id) .ThenBy < CrossJoinTableB >(x => x.Id);
デバッグ
db.GetLastSql().Print();