diff --git a/OrmTest/DataBase/script.sql b/OrmTest/DataBase/script.sql index 3598da94d..5c9d0927d 100644 Binary files a/OrmTest/DataBase/script.sql and b/OrmTest/DataBase/script.sql differ diff --git a/OrmTest/Demo/Delete.cs b/OrmTest/Demo/Delete.cs index 0dc19f7da..ba4cd58f9 100644 --- a/OrmTest/Demo/Delete.cs +++ b/OrmTest/Demo/Delete.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace OrmTest.Demo { - class Delete + public class Delete { } } diff --git a/OrmTest/Demo/Insert.cs b/OrmTest/Demo/Insert.cs index 25da9de83..c80976552 100644 --- a/OrmTest/Demo/Insert.cs +++ b/OrmTest/Demo/Insert.cs @@ -1,4 +1,6 @@ -using System; +using OrmTest.Models; +using SqlSugar; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +8,59 @@ using System.Threading.Tasks; namespace OrmTest.Demo { - class Insert + public class Insert { + public static void Init() { + var db = GetInstance(); + db.IgnoreColumns.Add("TestId", "Student"); + + var insertObj = new Student() { Name = "jack", CreateTime = Convert.ToDateTime("2010-1-1") ,SchoolId=1}; + + //Insert reutrn Insert Count + var t2 = db.Insertable(insertObj).ExecuteCommand(); + + //Insert reutrn Identity Value + var t3 = db.Insertable(insertObj).ExecuteReutrnIdentity(); + + + //Only insert Name + var t4 = db.Insertable(insertObj).InsertColumns(it => new { it.Name,it.SchoolId }).ExecuteReutrnIdentity(); + + + //Ignore TestId + var t5 = db.Insertable(insertObj).IgnoreColumns(it => new { it.Name, it.TestId }).ExecuteReutrnIdentity(); + + + //Ignore TestId + var t6 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").ExecuteReutrnIdentity(); + + + //Use Lock + var t8 = db.Insertable(insertObj).With(SqlWith.UpdLock).ExecuteCommand(); + + + var insertObj2 = new Student() { Name = null, CreateTime = Convert.ToDateTime("2010-1-1") }; + var t9 = db.Insertable(insertObj2).Where(true/* Is insert null */, true/*off identity*/).ExecuteCommand(); + + //Insert List + var insertObjs = new List(); + for (int i = 0; i < 1000; i++) + { + insertObjs.Add(new Student() { Name = "name" + i }); + } + var s9 = db.Insertable(insertObjs.ToArray()).InsertColumns(it => new { it.Name }).ExecuteCommand(); + } + + public static SqlSugarClient GetInstance() + { + SqlSugarClient db = new SqlSugarClient(new SystemTablesConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true }); + db.Ado.IsEnableLogEvent = true; + db.Ado.LogEventStarting = (sql, pars) => + { + Console.WriteLine(sql + "\r\n" + db.RewritableMethods.SerializeObject(pars)); + Console.WriteLine(); + }; + return db; + } } } diff --git a/OrmTest/Demo/Query.cs b/OrmTest/Demo/Query.cs index eb3e1fa1c..775a8f353 100644 --- a/OrmTest/Demo/Query.cs +++ b/OrmTest/Demo/Query.cs @@ -53,6 +53,7 @@ namespace OrmTest.Demo { var db = GetInstance(); var getAll = db.Queryable().ToList(); + var getAllNoLock = db.Queryable().With(SqlWith.NoLock).ToList(); var getByPrimaryKey = db.Queryable().InSingle(2); var getByWhere = db.Queryable().Where(it => it.Id == 1 || it.Name == "a").ToList(); var getByFuns = db.Queryable().Where(it => NBORM.IsNullOrEmpty(it.Name)).ToList(); diff --git a/OrmTest/Program.cs b/OrmTest/Program.cs index f2279c67b..2892d83ec 100644 --- a/OrmTest/Program.cs +++ b/OrmTest/Program.cs @@ -35,6 +35,7 @@ namespace OrmTest /***Demo***/ OrmTest.Demo.Query.Init(); + OrmTest.Demo.Insert.Init(); } } }