Skip to content

Commit

Permalink
- 优化 IUpdate 未使用 .Set 时忽略执行;#1694
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Dec 19, 2023
1 parent 231d5ac commit 03d3fe6
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 127 deletions.
18 changes: 14 additions & 4 deletions Examples/base_entity/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ static void Main(string[] args)

.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;min pool size=1;Max pool size=3;AllowLoadLocalInfile=true")

//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true")
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true")
//.UseAdoConnectionPool(false)
//.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=127.0.0.1;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=2")
////.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=127.0.0.1;Port=5432;Username=postgres;Password=123456;Database=toc;Pooling=true;Maximum Pool Size=2")
Expand Down Expand Up @@ -609,10 +609,20 @@ static void Main(string[] args)
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
#endregion

//fsql.CodeFirst.IsGenerateCommandParameterWithLambda = true;
//var TreeModel01 = fsql.Select<TreeModel>().Where(a => a.code == "x" && a.Childs.AsSelect().Any(b => b.id == a.id && b.status == ActivityStatusCode.Error)).ToList();
fsql.Update<User1>()
.Where(t => t.GroupId == 1)
.ExecuteUpdated();


fsql.Update<User1>()
.Where(t => t.GroupId == 1)
.SetIf(false, t => t.CreateTime == DateTime.Now)
.ExecuteUpdated();

//fsql.CodeFirst.IsGenerateCommandParameterWithLambda = true;
//var TreeModel01 = fsql.Select<TreeModel>().Where(a => a.code == "x" && a.Childs.AsSelect().Any(b => b.id == a.id && b.status == ActivityStatusCode.Error)).ToList();

var v1 = 123123123;
var v1 = 123123123;
var mysql0111 = fsql.Select<User1>().Where(a => a.Nickname.Contains(v1.ToString())).ToSql();
var mysql0112 = fsql.Select<User1>().Where(a => a.Nickname.Contains(123123123.ToString())).ToSql();
var v2 = "123123123";
Expand Down
9 changes: 0 additions & 9 deletions FreeSql.DbContext/FreeSql.DbContext.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

210 changes: 98 additions & 112 deletions FreeSql/FreeSql.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions FreeSql/Internal/CommonProvider/UpdateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,8 @@ public void ToSqlFetch(Action<StringBuilder> fetch)
return;
}
if (_where.Length == 0) return;
var newwhere = new StringBuilder();
if (_set.Length == 0 && _setIncr.Length == 0) return;
var newwhere = new StringBuilder();
ToSqlWhere(newwhere);

var sb = new StringBuilder();
Expand Down Expand Up @@ -1004,6 +1005,7 @@ async public Task ToSqlFetchAsync(Func<StringBuilder, Task> fetchAsync)
return;
}
if (_where.Length == 0) return;
if (_set.Length == 0 && _setIncr.Length == 0) return;
var newwhere = new StringBuilder();
ToSqlWhere(newwhere);

Expand All @@ -1027,7 +1029,7 @@ async public Task ToSqlFetchAsync(Func<StringBuilder, Task> fetchAsync)
sb.Clear();
}
#endif
public virtual void ToSqlExtension110(StringBuilder sb, bool isAsTableSplited)
public virtual void ToSqlExtension110(StringBuilder sb, bool isAsTableSplited)
{
if (_where.Length == 0 && _source.Any() == false) return;
if (_source.Any() == false && _set.Length == 0 && _setIncr.Length == 0) return;
Expand Down

0 comments on commit 03d3fe6

Please sign in to comment.