Home > Backend Development > C#.Net Tutorial > szq.orm.sql detailed usage example code

szq.orm.sql detailed usage example code

零下一度
Release: 2017-06-23 16:04:57
Original
1512 people have browsed it

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

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


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


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


           //插入
           int row1 = db.Insert(new Config { Name = "a" });
           int row2 = db.InsertBatch(new List {
           new Config { Name = "b" },
           new Config { Name = "c" }
           });


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


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

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

 

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

The above is the detailed content of szq.orm.sql detailed usage example code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template