mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-02 03:13:58 +08:00
-
This commit is contained in:
59
OrmTest/UnitTest/Update.cs
Normal file
59
OrmTest/UnitTest/Update.cs
Normal file
@@ -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<Student>() { 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<T>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,8 +13,9 @@ namespace SqlSugar
|
|||||||
IInsertable<T> With(string lockString);
|
IInsertable<T> With(string lockString);
|
||||||
IInsertable<T> Update(T InsertObj);
|
IInsertable<T> Update(T InsertObj);
|
||||||
IInsertable<T> Where(bool isUpdateNull);
|
IInsertable<T> Where(bool isUpdateNull);
|
||||||
IInsertable<T> UpdateColumns(Expression<Func<T, object[]>> columns);
|
IInsertable<T> UpdateColumns(Expression<Func<T, object>> columns);
|
||||||
IInsertable<T> IgnoreColumns(Expression<Func<T, object[]>> columns);
|
IInsertable<T> IgnoreColumns(Expression<Func<T, object>> columns);
|
||||||
IInsertable<T> UpdateRange(List<T> InsertObjs);
|
IInsertable<T> UpdateRange(List<T> InsertObjs);
|
||||||
|
object ToSql();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user