SqlSugar源码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB

8 years ago
# SqlSugar 4.X
8 years ago
8 years ago
## 1. Query
8 years ago
8 years ago
### 1.1 Create Connection
8 years ago
```c
8 years ago
SqlSugarClient db = new SqlSugarClient(new SystemTableConfig()
{ ConnectionString = Config.ConnectionString, DbType =DbType.SqlServer, IsAutoCloseConnection = true });
8 years ago
```
8 years ago
### 1.2 Introduction
8 years ago
```c
var getAll = db.Queryable<Student>().ToList();
var getAllNoLock = db.Queryable<Student>().With(SqlWith.NoLock).ToList();
var getByPrimaryKey = db.Queryable<Student>().InSingle(2);
var getByWhere = db.Queryable<Student>().Where(it => it.Id == 1 || it.Name == "a").ToList();
var getByFuns = db.Queryable<Student>().Where(it => NBORM.IsNullOrEmpty(it.Name)).ToList();
```
8 years ago
8 years ago
###1.3 Page
```c
var pageIndex = 1;
var pageSize = 2;
var totalCount = 0;
//page
var page = db.Queryable<Student>().ToPageList(pageIndex, pageSize, ref totalCount);
//page join
var pageJoin = db.Queryable<Student, School>((st, sc) => new object[] {
JoinType.Left,st.SchoolId==sc.Id
}).ToPageList(pageIndex, pageSize, ref totalCount);
//top 5
var top5 = db.Queryable<Student>().Take(5).ToList();
//skip5
var skip5 = db.Queryable<Student>().Skip(5).ToList();
```