mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-25 01:14:33 +08:00
Update Updateable
This commit is contained in:
parent
152e779bfa
commit
599456fcda
@ -8,8 +8,8 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
public class Config
|
public class Config
|
||||||
{
|
{
|
||||||
public static string ConnectionString = "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=haosql";
|
public static string ConnectionString2 = "server=localhost;Database=SQLSUGAR4XTEST;Uid=root;Pwd=root";
|
||||||
public static string ConnectionString3 = "server=localhost;Database=sqlsugar4xtest;Uid=root;Pwd=haosql";
|
public static string ConnectionString3 = "server=localhost;Database=sqlsugar4xtest;Uid=root;Pwd=root";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,13 @@ namespace OrmTest.Demo
|
|||||||
|
|
||||||
//Column is null no update
|
//Column is null no update
|
||||||
db.Updateable(updateObj).Where(true).ExecuteCommand();
|
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(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" } }).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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,6 +122,11 @@ namespace OrmTest.Demo
|
|||||||
|
|
||||||
|
|
||||||
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)
|
private static int GeneratePassword(int v1, int v2)
|
||||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
@ -188,10 +189,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
var isFirst = whereString == null;
|
var isFirst = whereString == null;
|
||||||
whereString += (isFirst ? null : " AND ");
|
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)
|
foreach (var item in PrimaryKeys)
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SqlSugar
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
@ -70,10 +71,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
var isFirst = whereString == null;
|
var isFirst = whereString == null;
|
||||||
whereString += (isFirst ? null : " AND ");
|
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)
|
foreach (var item in PrimaryKeys)
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,7 @@ namespace SqlSugar
|
|||||||
foreach (var item in pkList)
|
foreach (var item in pkList)
|
||||||
{
|
{
|
||||||
var isFirst = pkList.First() == item;
|
var isFirst = pkList.First() == item;
|
||||||
var whereString = isFirst ? " " : " AND ";
|
var whereString = "";
|
||||||
whereString += GetOracleUpdateColums(item);
|
whereString += GetOracleUpdateColums(item);
|
||||||
whereList.Add(whereString);
|
whereList.Add(whereString);
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -60,6 +60,12 @@ namespace OrmTest.Demo
|
|||||||
db.Updateable(updateObj).Where(true).ExecuteCommand();
|
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" } }).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