mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update Updateable
This commit is contained in:
parent
152e779bfa
commit
599456fcda
@ -8,8 +8,8 @@ namespace OrmTest
|
||||
{
|
||||
public class Config
|
||||
{
|
||||
public static string ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=haosql";
|
||||
public static string ConnectionString2 = "server=localhost;Database=SQLSUGAR4XTEST;Uid=root;Pwd=haosql";
|
||||
public static string ConnectionString3 = "server=localhost;Database=sqlsugar4xtest;Uid=root;Pwd=haosql";
|
||||
public static string ConnectionString = "server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=root";
|
||||
public static string ConnectionString2 = "server=localhost;Database=SQLSUGAR4XTEST;Uid=root;Pwd=root";
|
||||
public static string ConnectionString3 = "server=localhost;Database=sqlsugar4xtest;Uid=root;Pwd=root";
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,13 @@ namespace OrmTest.Demo
|
||||
|
||||
//Column is null no update
|
||||
db.Updateable(updateObj).Where(true).ExecuteCommand();
|
||||
|
||||
|
||||
db.Updateable(new Student[] { new Student() { Id = 2, Name = "a2" }, new Student() { Id = 1, Name = "a1" } })
|
||||
.UpdateColumns(it => new { it.Name, it.Id, it.SchoolId })
|
||||
.WhereColumns(it=>new { it.SchoolId})
|
||||
.Where(it => it.Id == 1)
|
||||
.ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,6 +66,12 @@ namespace OrmTest.Demo
|
||||
db.Updateable(updateObj).Where(true).ExecuteCommand();
|
||||
|
||||
db.Updateable(new Student[] { new Student() { Id=2, Name="a2" }, new Student() { Id = 1, Name = "a1" } }).ExecuteCommand();
|
||||
|
||||
db.Updateable(new Student[] { new Student() { Id = 2, Name = "a2" }, new Student() { Id = 1, Name = "a1" } })
|
||||
.UpdateColumns(it => new { it.Name, it.Id, it.SchoolId })
|
||||
.WhereColumns(it => it.Name)
|
||||
.Where(it => it.Id == 1)
|
||||
.ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,25 +57,25 @@ namespace OrmTest.Demo
|
||||
//Update Student set Name='jack' Where Id=1
|
||||
|
||||
//Column is null no update
|
||||
db.Updateable(updateObj).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommand();
|
||||
db.Updateable(updateObj).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
||||
|
||||
//sql
|
||||
db.Updateable(updateObj).Where("id=@x",new { x="1"}).ExecuteCommand();
|
||||
db.Updateable(updateObj).Where("id","=",1).ExecuteCommand();
|
||||
db.Updateable(updateObj).Where("id=@x", new { x = "1" }).ExecuteCommand();
|
||||
db.Updateable(updateObj).Where("id", "=", 1).ExecuteCommand();
|
||||
var t12 = db.Updateable<School>().AS("Student").UpdateColumns(it => new School() { Name = "jack" }).Where(it => it.Id == 1).ExecuteCommandAsync();
|
||||
t12.Wait();
|
||||
|
||||
//update one columns
|
||||
var count = db.Updateable<Student>().UpdateColumns(it => it.SchoolId == it.SchoolId).Where(it => it.Id == it.Id+1).ExecuteCommand();
|
||||
var count = db.Updateable<Student>().UpdateColumns(it => it.SchoolId == it.SchoolId).Where(it => it.Id == it.Id + 1).ExecuteCommand();
|
||||
|
||||
var count1 = db.Updateable<Student>()
|
||||
.UpdateColumnsIF(false,it => it.SchoolId == it.SchoolId)//ignore
|
||||
.UpdateColumnsIF(false, it => it.SchoolId == it.SchoolId)//ignore
|
||||
.UpdateColumnsIF(true, it => it.SchoolId == 2).//ok
|
||||
Where(it => it.Id == it.Id + 1).ExecuteCommand();
|
||||
|
||||
|
||||
//update one columns
|
||||
var count2 = db.Updateable<Student>().UpdateColumns(it => it.SchoolId == it.SchoolId+1).Where(it => it.Id == it.Id + 1).ExecuteCommand();
|
||||
var count2 = db.Updateable<Student>().UpdateColumns(it => it.SchoolId == it.SchoolId + 1).Where(it => it.Id == it.Id + 1).ExecuteCommand();
|
||||
|
||||
var dt = new Dictionary<string, object>();
|
||||
dt.Add("id", 1);
|
||||
@ -83,7 +83,7 @@ namespace OrmTest.Demo
|
||||
dt.Add("createTime", DateTime.Now);
|
||||
var t66 = db.Updateable(dt).AS("student").WhereColumns("id").With(SqlWith.UpdLock).ExecuteCommand();
|
||||
|
||||
db.Updateable(new Student() { Id = 1 }).UpdateColumns(new string[] { "name" }).Where(it=>it.Name=="1").ExecuteCommand();
|
||||
db.Updateable(new Student() { Id = 1 }).UpdateColumns(new string[] { "name" }).Where(it => it.Name == "1").ExecuteCommand();
|
||||
|
||||
var dt2 = new Dictionary<string, object>();
|
||||
dt2.Add("id", 2);
|
||||
@ -99,35 +99,40 @@ namespace OrmTest.Demo
|
||||
{
|
||||
SchoolId = SqlFunc.IIF(p.Id == 1, 2, 3)
|
||||
}).Where(p => p.Id == 10000).ExecuteCommand();
|
||||
var t21= db.Updateable<Student>().UpdateColumns(p => new Student()
|
||||
var t21 = db.Updateable<Student>().UpdateColumns(p => new Student()
|
||||
{
|
||||
SchoolId = SqlFunc.IF(p.Id==1).Return(1).End(p.Id)
|
||||
SchoolId = SqlFunc.IF(p.Id == 1).Return(1).End(p.Id)
|
||||
}).Where(p => p.Id == 10000).ExecuteCommand();
|
||||
|
||||
|
||||
var t22= db.Updateable<Student>().UpdateColumns(p => new Student()
|
||||
var t22 = db.Updateable<Student>().UpdateColumns(p => new Student()
|
||||
{
|
||||
SchoolId = SqlFunc.Subqueryable<Student>().Where(s=>s.SchoolId==p.Id).Select(s=>s.Id)
|
||||
SchoolId = SqlFunc.Subqueryable<Student>().Where(s => s.SchoolId == p.Id).Select(s => s.Id)
|
||||
}).Where(p => p.Id == 10000).ExecuteCommand();
|
||||
|
||||
|
||||
var t23= db.Updateable<Student>(new Student() { })
|
||||
var t23 = db.Updateable<Student>(new Student() { })
|
||||
.Where(p => p.SchoolId == SqlFunc.Subqueryable<Student>().Where(s => s.SchoolId == p.Id).Select(s => s.Id)).ExecuteCommand();
|
||||
|
||||
var t24 = db.Updateable(new Student() { }).WhereColumns(it=>it.CreateTime).ExecuteCommand();
|
||||
var t24 = db.Updateable(new Student() { }).WhereColumns(it => it.CreateTime).ExecuteCommand();
|
||||
|
||||
var t25 = db.Updateable(new Student() { }).UpdateColumns(it=> new { it.Name,it.CreateTime}).WhereColumns(it => it.CreateTime).ExecuteCommand();
|
||||
var t25 = db.Updateable(new Student() { }).UpdateColumns(it => new { it.Name, it.CreateTime }).WhereColumns(it => it.CreateTime).ExecuteCommand();
|
||||
|
||||
var t26 = db.Updateable(new List<Student>() { new Student() { }, new Student() { } }).UpdateColumns(it => new { it.Name, it.CreateTime }).WhereColumns(it => it.CreateTime).ExecuteCommand();
|
||||
|
||||
|
||||
db.Updateable<Student>().UpdateColumns(it => new Student { SchoolId = GeneratePassword(2, 1), Name =SqlFunc.ToString(it.Name), CreateTime = DateTime.Now.AddDays(1) }).Where(it => it.Id == 1).ExecuteCommand();
|
||||
db.Updateable<Student>().UpdateColumns(it => new Student { SchoolId = GeneratePassword(2, 1), Name = SqlFunc.ToString(it.Name), CreateTime = DateTime.Now.AddDays(1) }).Where(it => it.Id == 1).ExecuteCommand();
|
||||
db.Updateable(new Student[] { new Student() { Id = 2, Name = "a2" }, new Student() { Id = 1, Name = "a1" } })
|
||||
.UpdateColumns(it => new { it.Name, it.Id, it.SchoolId })
|
||||
.WhereColumns(it => it.Name)
|
||||
.Where(it => it.Id == 1)
|
||||
.ExecuteCommand();
|
||||
}
|
||||
|
||||
private static int GeneratePassword(int v1, int v2)
|
||||
{
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
@ -188,10 +189,10 @@ namespace SqlSugar
|
||||
{
|
||||
var isFirst = whereString == null;
|
||||
whereString += (isFirst ? null : " AND ");
|
||||
whereString += item;
|
||||
whereString += Regex.Replace(item,"\\"+this.Builder.SqlTranslationLeft,"T."+ this.Builder.SqlTranslationLeft);
|
||||
}
|
||||
}
|
||||
else if (PrimaryKeys.HasValue())
|
||||
if (PrimaryKeys.HasValue())
|
||||
{
|
||||
foreach (var item in PrimaryKeys)
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
@ -70,10 +71,10 @@ namespace SqlSugar
|
||||
{
|
||||
var isFirst = whereString == null;
|
||||
whereString += (isFirst ? null : " AND ");
|
||||
whereString += item;
|
||||
whereString += Regex.Replace(item, " \\" + this.Builder.SqlTranslationLeft, "T." + this.Builder.SqlTranslationLeft);
|
||||
}
|
||||
}
|
||||
else if (PrimaryKeys.HasValue())
|
||||
if (PrimaryKeys.HasValue())
|
||||
{
|
||||
foreach (var item in PrimaryKeys)
|
||||
{
|
||||
|
@ -19,7 +19,7 @@ namespace SqlSugar
|
||||
foreach (var item in pkList)
|
||||
{
|
||||
var isFirst = pkList.First() == item;
|
||||
var whereString = isFirst ? " " : " AND ";
|
||||
var whereString = "";
|
||||
whereString += GetOracleUpdateColums(item);
|
||||
whereList.Add(whereString);
|
||||
}
|
||||
|
Binary file not shown.
@ -60,6 +60,12 @@ namespace OrmTest.Demo
|
||||
db.Updateable(updateObj).Where(true).ExecuteCommand();
|
||||
|
||||
db.Updateable(new Student[] { new Student() { Id = 2, Name = "a2" }, new Student() { Id = 1, Name = "a1" } }).ExecuteCommand();
|
||||
|
||||
db.Updateable(new Student[] { new Student() { Id = 2, Name = "a2" }, new Student() { Id = 1, Name = "a1" } })
|
||||
.UpdateColumns(it => new { it.Name, it.Id, it.SchoolId })
|
||||
.WhereColumns(it => it.Name)
|
||||
.Where(it => it.Id == 1)
|
||||
.ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user