码迷,mamicode.com
首页 > 数据库 > 详细

szq.orm.sql详细使用说明

时间:2017-06-09 11:14:16      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:get   str   manager   query   st3   条件查询   bsp   val   ati   

var connStr = ConfigurationManager.ConnectionStrings["dbconnstr"].ConnectionString;

SQLContext db = new SQLContext(connStr);
//list查询
var list1 = db.GetList<Config>(s => s.ID > 5);
var list2 = db.GetList<Config>("select * from BAS_Config where id > @id", null, new SqlParameter("@id", 5));
var list3 = db.Query<Config>().Where(s => s.ID > 5).ToList();


//多条件查询
var query = db.Query<Config>();
query.Where(s => s.ParamType == "b");
query.Where(s => s.ID > 5);
var result = query.ToList();


//分页查询
var pageResult1 = db.GetPageResult<Config>(new SQL.PageHelper.PageBase { PageIndex = 0, PageSize = 10 }, s => s.ID, true);
var pageResult2 = db.GetPageResult<Config>(new SQL.PageHelper.PageBase { PageIndex = 0, PageSize = 10 }, "select * from BAS_Config", "Id asc");
var pageResult3 = db.Query<Config>().ToPageResult(new SQL.PageHelper.PageBase { PageIndex = 0, PageSize = 10 }, s => s.ID, true);


//插入
int row1 = db.Insert<Config>(new Config { ParamID = "a", ParamType = "a", ParamValue = "a" }, false);
int row2 = db.InsertBatch<Config>(new List<Config> {
new Config { ParamID = "b", ParamType = "b", ParamValue = "b" },
new Config { ParamID = "c", ParamType = "c", ParamValue = "c" }
});


//更新
int update1 = db.Update<Config>(new Config { ID = 10033, ParamID = "aaa", ParamType = "aaa", ParamValue = "aaa", Remark = "aa" });
int update2 = db.Query<Config>().Set(s => s.ParamID, "aaa").Set(s => s.ParamType, "aaa").Where(s => s.ID == 10033).Update();


//删除
int delete1 = db.Delete<Config>(s => s.ID == 10033);
int delete2 = db.Query<Config>().Where(s => s.ID == 10033).Delete();

 

szq.orm.sql详细使用说明

标签:get   str   manager   query   st3   条件查询   bsp   val   ati   

原文地址:http://www.cnblogs.com/wuyifeixiang/p/6970781.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!