首页 > 数据库技术 > 详细

szq.orm.sql详细使用说明

时间:2017-06-09 10:47:10      阅读:318      评论:0      收藏:0      [点我收藏+]

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详细使用说明

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!