Update README.md

This commit is contained in:
sunkaixuan
2019-04-29 15:17:36 +08:00
committed by GitHub
parent 35ab5c84d6
commit f936c8903a

View File

@@ -22,41 +22,41 @@ Install-Package sqlSugarCore
All operations are based on SqlSugarClient All operations are based on SqlSugarClient
```cs ```cs
public List<Student> GetStudentList() public List<Student> GetStudentList()
{ {
var db= GetInstance(); var db= GetInstance();
var list= db.Queryable<Student>().ToList();//Search var list= db.Queryable<Student>().ToList();//Search
return list; return list;
} }
/// <summary> /// <summary>
/// Create SqlSugarClient /// Create SqlSugarClient
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
private SqlSugarClient GetInstance() private SqlSugarClient GetInstance()
{
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{ {
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() ConnectionString = "Server=.xxxxx",
{ DbType = DbType.SqlServer,
ConnectionString = "Server=.xxxxx", IsAutoCloseConnection = true,
DbType = DbType.SqlServer, InitKeyType = InitKeyType.Attribute
IsAutoCloseConnection = true, });
InitKeyType = InitKeyType.Attribute //Print sql
}); db.Aop.OnLogExecuting = (sql, pars) =>
//Print sql {
db.Aop.OnLogExecuting = (sql, pars) => Console.WriteLine(sql + "\r\n" + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
{ Console.WriteLine();
Console.WriteLine(sql + "\r\n" + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value))); };
Console.WriteLine(); return db;
}; }
return db;
}
public class Student public class Student
{ {
[SugarColumn(IsPrimaryKey = true, IsIdentity = true] [SugarColumn(IsPrimaryKey = true, IsIdentity = true]
public int Id { get; set; } public int Id { get; set; }
public int? SchoolId { get; set; } public int? SchoolId { get; set; }
public string Name { get; set; } public string Name { get; set; }
} }
``` ```
## SqlSugar's 16 Functions ## SqlSugar's 16 Functions