Browse Source

Update Updateable

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
599456fcda
  1. 6
      Src/Asp.Net/MySqlTest/Config.cs
  2. 7
      Src/Asp.Net/MySqlTest/Demos/2_Update.cs
  3. 6
      Src/Asp.Net/OracleTest/Demos/2_Update.cs
  4. 5
      Src/Asp.Net/SqlServerTest/Demos/2_Update.cs
  5. 5
      Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs
  6. 5
      Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs
  7. 2
      Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteUpdateBuilder.cs
  8. BIN
      Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite
  9. 6
      Src/Asp.Net/SqliteTest/Demos/2_Update.cs

6
Src/Asp.Net/MySqlTest/Config.cs

@ -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";
} }
} }

7
Src/Asp.Net/MySqlTest/Demos/2_Update.cs

@ -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();
} }
} }
} }

6
Src/Asp.Net/OracleTest/Demos/2_Update.cs

@ -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();
} }
} }
} }

5
Src/Asp.Net/SqlServerTest/Demos/2_Update.cs

@ -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)

5
Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs

@ -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)
{ {

5
Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs

@ -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)
{ {

2
Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteUpdateBuilder.cs

@ -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);
} }

BIN
Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite

Binary file not shown.

6
Src/Asp.Net/SqliteTest/Demos/2_Update.cs

@ -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…
Cancel
Save