From 58c818ab313b612b19cc348c0b61cb503adddac9 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Wed, 17 May 2017 00:22:29 +0800 Subject: [PATCH] - --- OrmTest/UnitTest/Update.cs | 59 +++++++++++++++++++++++++++++++ SqlSugar/Interface/IUpdateable.cs | 5 +-- 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 OrmTest/UnitTest/Update.cs diff --git a/OrmTest/UnitTest/Update.cs b/OrmTest/UnitTest/Update.cs new file mode 100644 index 000000000..2a5de9bd6 --- /dev/null +++ b/OrmTest/UnitTest/Update.cs @@ -0,0 +1,59 @@ +using OrmTest.Models; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OrmTest.UnitTest +{ + public class Update:ExpTestBase + { + private Update() { } + public Update(int eachCount) + { + this.Count = eachCount; + } + + public void Init() + { + var db = GetInstance(); + var updateObj = new Student() { Id=1,Name = "jack", CreateTime = DateTime.Now }; + var updateObjs = new List() { updateObj }.ToArray(); + db.IgnoreColumns.Add("TestId", "Student"); + //db.MappingColumns.Add("id","dbid", "Student"); + + var s1 = db.Updateable(updateObj).ToSql(); + + //Insert reutrn Command Count + var s2 = db.Updateable(updateObj).ExecuteCommand(); + + db.IgnoreColumns = null; + //Only insert Name + var s3 = db.Updateable(updateObj).UpdateColumns(it => new { it.Name}).ToSql(); + + //Ignore Name and TestId + var s4 = db.Updateable(updateObj).IgnoreColumns(it => new { it.Name, it.TestId }).ToSql(); + + //Ignore Name and TestId + var s5 = db.Updateable(updateObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ToSql(); + + //Use Lock + var s6 = db.Updateable(updateObj).With(SqlWith.UpdLock).ToSql(); + + //ToSql + var s7 = db.Insertable(updateObj).With(SqlWith.UpdLock) + .InsertColumns(it => new { it.Name }).ToSql(); + + //Insert List + var s8 = db.Updateable(updateObj).With(SqlWith.UpdLock).ToSql(); + } + + public SqlSugarClient GetInstance() + { + SqlSugarClient db = new SqlSugarClient(new SystemTablesConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true }); + return db; + } + } +} diff --git a/SqlSugar/Interface/IUpdateable.cs b/SqlSugar/Interface/IUpdateable.cs index a74a0af2d..812e8d753 100644 --- a/SqlSugar/Interface/IUpdateable.cs +++ b/SqlSugar/Interface/IUpdateable.cs @@ -13,8 +13,9 @@ namespace SqlSugar IInsertable With(string lockString); IInsertable Update(T InsertObj); IInsertable Where(bool isUpdateNull); - IInsertable UpdateColumns(Expression> columns); - IInsertable IgnoreColumns(Expression> columns); + IInsertable UpdateColumns(Expression> columns); + IInsertable IgnoreColumns(Expression> columns); IInsertable UpdateRange(List InsertObjs); + object ToSql(); } }