Skip to content

Commit 09225ff

Browse files
committed
- 优化 IUpdateJoin AsTable 同时对多表名设置;
1 parent 632c5ca commit 09225ff

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

Examples/base_entity/Program.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ static void Main(string[] args)
559559
//.UseConnectionString(FreeSql.DataType.Firebird, @"database=localhost:D:\fbdata\EXAMPLES.fdb;user=sysdba;password=123456;max pool size=5")
560560
//.UseQuoteSqlName(false)
561561

562-
//.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")
562+
.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")
563563

564564
//.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true")
565565

@@ -600,6 +600,12 @@ static void Main(string[] args)
600600
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
601601
#endregion
602602

603+
var updatejoin031sql = fsql.Update<User1>()
604+
.Join<UserGroup>((a, b) => a.GroupId == b.Id)
605+
.AsTable("t1", "t2")
606+
.Set((a, b) => b.GroupName == a.Username + "b.groupname")
607+
.ToSql();
608+
603609
fsql.CodeFirst.Entity<B11>(e =>
604610
{
605611
e.Help().Navigate(b => b.a, nameof(B11.Id));
@@ -618,11 +624,6 @@ static void Main(string[] args)
618624

619625
fsql.GlobalFilter.Apply<User1>("test01", a => a.IsDeleted == false);
620626

621-
var updatejoin031sql = fsql.Update<User1>()
622-
.Join<UserGroup>((a, b) => a.GroupId == b.Id)
623-
.Set((a, b) => b.GroupName == a.Username + "b.groupname")
624-
.ToSql();
625-
626627
fsql.UseJsonMap();
627628
fsql.Select<MiDevice>().Where(a => a.FormLocking == null).Count();
628629

FreeSql.DbContext/FreeSql.DbContext.xml

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FreeSql/FreeSql.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FreeSql/Interface/Curd/IUpdateJoin.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ public interface IUpdateJoin<T1, T2>
106106
/// 设置表名
107107
/// </summary>
108108
/// <param name="tableName"></param>
109+
/// <param name="joinTableName"></param>
109110
/// <returns></returns>
110-
IUpdateJoin<T1, T2> AsTable(string tableName);
111+
IUpdateJoin<T1, T2> AsTable(string tableName, string joinTableName);
111112
/// <summary>
112113
/// 返回即将执行的SQL语句
113114
/// </summary>

FreeSql/Internal/CommonProvider/UpdateJoinProvider.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,15 @@ public void ValidateDataType(Action InterceptSqlServer, Action InterceptMySql, A
9898
}
9999

100100
#region proxy IUpdate
101-
public IUpdateJoin<T1, T2> AsTable(string tableName)
101+
public IUpdateJoin<T1, T2> AsTable(string tableName, string joinTableName)
102102
{
103103
_update.AsTable(tableName);
104+
_query2Provider._tableRules.Clear();
105+
_query2Provider._tableRules.Add((t, old) =>
106+
{
107+
if (t == typeof(T2)) return joinTableName;
108+
return old;
109+
});
104110
return this;
105111
}
106112
public IUpdateJoin<T1, T2> WithConnection(DbConnection connection)

0 commit comments

Comments
 (0)