Dos.ORM Select查询 自定义列
自定义列
.Select( p = >new{ test = p.id}) // 同sql 列名 as 新列名
如下是
自己在写代码的例子,查询,分页,where条件,排序
var where = new Where<INCOM_TERMINALFAULT>(); where.And(a=>a.SA==1); where.And<X_CAR_DATABASE>((a, b) => b.CARNUMBERSID.Like("2"));
where.And(a=>a.CREATETIME >= DateTime.Parse("2017/1/17") && a.CREATETIME<DateTime.Parse("2017/1/18").AddDays(1) );//时间条件查询 DataTable table = Db.Context.From<INCOM_TERMINALFAULT>() .Select( p = >new{ test = p.CARID}) //查询自定义列,同sql 列名 as 新列名 // .Select(INCOM_TERMINALFAULT._.All, X_CAR_DATABASE._.CARNUMBERSID) 查询原有的列 .LeftJoin<X_CAR_DATABASE>((a, b) => a.CARID == b.ID) //左连接 ,lambda表达式 ,同sql on a.carid=b.id .Where(where) //过滤条件 .OrderBy(INCOM_TERMINALFAULT._.STARTTIME.Desc) //排序 .Page(10,2) //分页 .ToDataTable();
查询示例(Lambda表达式写法):
DB.Context.From<Dos.Model.TableName>() .Select(d => new { d.ID, d.Price }) //select ID,Price from TableName .Where(d => (d.ID == 2 && d.Name != "itdos" && d.Name.In("com","net","cn") && ) || d.Sex != null) // where (id=2 and Name<>'itdos' and Name in('com','net','cn')) or Sex is not null .GroupBy(d => new { d.Name, d.Sex }) //group by Name,Sex .OrderBy(d => new { d.CreateTime, d.Name }) //order by CreateTime,Name .Having(d => d.Name != '') //having Name<>'' .Top(5) .Page(10, 2) //分页返回结果 每页10条返回第2页数据 .ToList(); //返回实体列表 //.ToFirst(); //返回第一个实体 //.ToFirstDefault(); //返回第一个实体,如果为null,则默认实例化一个 //.ToDataSet(); //返回DataSet //.ToDataReader(); //返回IDataReader //.ToDataTable(); //返回DataTable //.ToScalar(); //返回单个值
备注:
Dosorm 增删该查 参见 http://www.itdos.com/Dos/ORM/BaseOperate.html
版权声明:本文为博主原创文章,转载请注明出处。http://www.cnblogs.com/SweetMemory/p/6269856.html