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 });
//如發現不支援上述語句,請下載最新版本