欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

szq.orm.sql详细使用实例代码

程序员文章站 2022-03-05 14:43:18
...
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 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.Name == "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 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 { Name = "a" });
int row2 = db.InsertBatch<Config>(new List<Config> {
new Config { Name = "b" },
new Config { Name = "c" }
});


//更新
int update1 = db.Update<Config>(new Config { ID = 10033, Name= "aa" });
int update2 = db.Query<Config>().Set(s => s.Name, "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();

int delete3 = db.Delete<Config>(new Config { ID = 10035 });

//如发现不支持上述语句,请下载最新版本

以上就是szq.orm.sql详细使用实例代码的详细内容,更多请关注其它相关文章!