//查所有 List<Student> list = db.Queryable<Student>().ToList(); //分页 int pageIndex = 1; int pageSize = 20; int totalCount=0; //单表分页 var page = db.Queryable<Student>().ToPageList(pageIndex, pageSize, ref totalCount);
Student item = db.Queryable<Student>().First(it=>it.Id==1);
DataTable dataTable = db.Queryable<Student>().ToDataTable();
var json = db.Queryable<Student>().ToJson(); //等同于Tolist转json //序列化时间格式 https://www.donet5.com/ask/14/13955 //SerializeDateTimeFormat
//表达式返回字典 Dictionary<string,object> dc = db.Queryable<Order>().ToDictionary(it=>it.Id,it=>it.Name); //多表查询Key和Value不在一个表 xxx.Select((x,y)=>new {xkey=x.id,yvalue=y.name}).MergeTable().ToDictionary(it=>it.xkey,it=>it.yvalue); //动态Sql返回字典 Dictionary<string,object> dc = db.Queryable<Order>() .Select<KeyValuePair<string,object>>("id as id1,name as name1") .ToList().ToDictionary(it=>it.Key,it=>it.Value);
List<Dictionary<string, object>> dcList = db.Queryable<Order>().ToDictionaryList();;
行列转换,行专列
var test01 = db.Queryable<Order>() .ToPivotTable(it => it.Id, it => it.Name, it => it.Sum(x => x.Price));//返回Datatable var test02 = db.Queryable<Order>() .ToPivotList(it => it.Id, it => it.Name, it => it.Sum(x => x.Price));//返回List<dynamic><br> var test03 = db.Queryable<Order>() .ToPivotJson(it => it.Id, it => it.Name, it => it.Sum(x => x.Price));//返回Json //统计出现非空错误可以加逻辑 it => it.Count()>0 ? it.Sum(x.Price):0) //可以多列 it=>new {name,id}
var sqlinfo= db.Queryable<Student>().ToSql();
当你想把匿名对象换成ViewModel的时候可以快速的建类
var classString= db.Queryable<Student>().Select(it=>new { id=it.id,name=it.name }).ToClassString();
db.Queryable<Student>().Count(); db.Queryable<Student>().Any(); db.Queryable<Student>().Max(); db.Queryable<Student>().Min();
2016 © donet5.comApache Licence 2.0