szq.orm.sql詳細使用執行個體代碼

來源:互聯網
上載者:User
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 });

//如發現不支援上述語句,請下載最新版本

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.