mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	FreeSql ISelect/IUpdate/IInsert/IDelete 增加 AsTable 方法,实现分表
This commit is contained in:
		@@ -32,5 +32,9 @@ namespace FreeSql {
 | 
				
			|||||||
			await _fsql.Insert<TEntity>().AppendData(entity).ExecuteAffrowsAsync();
 | 
								await _fsql.Insert<TEntity>().AppendData(entity).ExecuteAffrowsAsync();
 | 
				
			||||||
			return entity;
 | 
								return entity;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public virtual string ToDataTable(TEntity entity) {
 | 
				
			||||||
 | 
								return null;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,7 +13,7 @@ namespace FreeSql.Tests.DataAnnotations {
 | 
				
			|||||||
				//})
 | 
									//})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				.ConfigEntity(typeof(TestFluenttb1), a => {
 | 
									.ConfigEntity(typeof(TestFluenttb1), a => {
 | 
				
			||||||
					a.Name("xxdkdkdk1222").SelectFilter("a.Id22 > 1");
 | 
										a.Name("xxdkdkdk1222").SelectFilter("a.Id22dd > 1");
 | 
				
			||||||
					a.Property("Id").Name("Id22dd").IsIdentity(true);
 | 
										a.Property("Id").Name("Id22dd").IsIdentity(true);
 | 
				
			||||||
					a.Property("Name").DbType("varchar(101)").IsNullable(true);
 | 
										a.Property("Name").DbType("varchar(101)").IsNullable(true);
 | 
				
			||||||
				})
 | 
									})
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -68,5 +68,21 @@ namespace FreeSql.Tests.MySql {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			//delete.Where(a => a.Id > 0).ExecuteDeleted();
 | 
								//delete.Where(a => a.Id > 0).ExecuteDeleted();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								Assert.Null(g.mysql.Delete<Topic>().ToSql());
 | 
				
			||||||
 | 
								var sql = g.mysql.Delete<Topic>(new[] { 1, 2 }).AsTable(a => "TopicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM `TopicAsTable` WHERE (`Id` = 1 OR `Id` = 2)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = g.mysql.Delete<Topic>(new Topic { Id = 1, Title = "test" }).AsTable(a => "TopicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM `TopicAsTable` WHERE (`Id` = 1)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = g.mysql.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).AsTable(a => "TopicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM `TopicAsTable` WHERE (`Id` = 1 OR `Id` = 2)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = g.mysql.Delete<Topic>(new { id = 1 }).AsTable(a => "TopicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM `TopicAsTable` WHERE (`Id` = 1)", sql);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -81,5 +81,35 @@ namespace FreeSql.Tests.MySql {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			//insert.AppendData(items.First()).ExecuteInserted();
 | 
								//insert.AppendData(items.First()).ExecuteInserted();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								var items = new List<Topic>();
 | 
				
			||||||
 | 
								for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newTitle{a}", Clicks = a * 100 });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								var sql = insert.AppendData(items.First()).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO `Topic_InsertAsTable`(`Clicks`, `Title`, `CreateTime`) VALUES(?Clicks0, ?Title0, ?CreateTime0)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO `Topic_InsertAsTable`(`Clicks`, `Title`, `CreateTime`) VALUES(?Clicks0, ?Title0, ?CreateTime0), (?Clicks1, ?Title1, ?CreateTime1), (?Clicks2, ?Title2, ?CreateTime2), (?Clicks3, ?Title3, ?CreateTime3), (?Clicks4, ?Title4, ?CreateTime4), (?Clicks5, ?Title5, ?CreateTime5), (?Clicks6, ?Title6, ?CreateTime6), (?Clicks7, ?Title7, ?CreateTime7), (?Clicks8, ?Title8, ?CreateTime8), (?Clicks9, ?Title9, ?CreateTime9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO `Topic_InsertAsTable`(`Title`) VALUES(?Title0), (?Title1), (?Title2), (?Title3), (?Title4), (?Title5), (?Title6), (?Title7), (?Title8), (?Title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO `Topic_InsertAsTable`(`Clicks`, `Title`) VALUES(?Clicks0, ?Title0), (?Clicks1, ?Title1), (?Clicks2, ?Title2), (?Clicks3, ?Title3), (?Clicks4, ?Title4), (?Clicks5, ?Title5), (?Clicks6, ?Title6), (?Clicks7, ?Title7), (?Clicks8, ?Title8), (?Clicks9, ?Title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO `Topic_InsertAsTable`(`Title`) VALUES(?Title0), (?Title1), (?Title2), (?Title3), (?Title4), (?Title5), (?Title6), (?Title7), (?Title8), (?Title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO `Topic_InsertAsTable`(`Clicks`, `Title`) VALUES(?Clicks0, ?Title0), (?Clicks1, ?Title1), (?Clicks2, ?Title2), (?Clicks3, ?Title3), (?Clicks4, ?Title4), (?Clicks5, ?Title5), (?Clicks6, ?Title6), (?Clicks7, ?Title7), (?Clicks8, ?Title8), (?Clicks9, ?Title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO `Topic_InsertAsTable`(`Clicks`, `Title`) VALUES(?Clicks0, ?Title0), (?Clicks1, ?Title1), (?Clicks2, ?Title2), (?Clicks3, ?Title3), (?Clicks4, ?Title4), (?Clicks5, ?Title5), (?Clicks6, ?Title6), (?Clicks7, ?Title7), (?Clicks8, ?Title8), (?Clicks9, ?Title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO `Topic_InsertAsTable`(`Clicks`) VALUES(?Clicks0), (?Clicks1), (?Clicks2), (?Clicks3), (?Clicks4), (?Clicks5), (?Clicks6), (?Clicks7), (?Clicks8), (?Clicks9)", sql);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -642,5 +642,69 @@ namespace FreeSql.Tests.MySql {
 | 
				
			|||||||
		[Fact]
 | 
							[Fact]
 | 
				
			||||||
		public void As() {
 | 
							public void As() {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								Func<Type, string, string> tableRule = (type, oldname) => {
 | 
				
			||||||
 | 
									if (type == typeof(Topic)) return oldname + "AsTable1";
 | 
				
			||||||
 | 
									else if (type == typeof(TestTypeInfo)) return oldname + "AsTable2";
 | 
				
			||||||
 | 
									return oldname + "AsTable";
 | 
				
			||||||
 | 
								};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a.Type<70><65>a.Type.Parent <20><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
				
			||||||
 | 
								var query = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid).AsTable(tableRule);
 | 
				
			||||||
 | 
								var sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, a__Type.`Guid`, a__Type.`ParentId`, a__Type.`Name`, a.`Title`, a.`CreateTime` FROM `tb_topicAsTable1` a LEFT JOIN `TestTypeInfoAsTable2` a__Type ON a__Type.`Guid` = a.`TestTypeInfoGuid`", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid && a.Type.Name == "xxx").AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, a__Type.`Guid`, a__Type.`ParentId`, a__Type.`Name`, a.`Title`, a.`CreateTime` FROM `tb_topicAsTable1` a LEFT JOIN `TestTypeInfoAsTable2` a__Type ON a__Type.`Guid` = a.`TestTypeInfoGuid` AND a__Type.`Name` = 'xxx'", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, a__Type.`Guid`, a__Type.`ParentId`, a__Type.`Name`, a.`Title`, a.`CreateTime` FROM `tb_topicAsTable1` a LEFT JOIN `TestTypeParentInfoAsTable` a__Type__Parent ON 1 = 1 LEFT JOIN `TestTypeInfoAsTable2` a__Type ON a__Type.`Guid` = a.`TestTypeInfoGuid` AND a__Type.`Name` = 'xxx' WHERE (a__Type__Parent.`Id` = 10)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
				
			||||||
 | 
								query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, b.`Guid`, b.`ParentId`, b.`Name`, a.`Title`, a.`CreateTime` FROM `tb_topicAsTable1` a LEFT JOIN `TestTypeInfoAsTable2` b ON b.`Guid` = a.`TestTypeInfoGuid`", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx").AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, b.`Guid`, b.`ParentId`, b.`Name`, a.`Title`, a.`CreateTime` FROM `tb_topicAsTable1` a LEFT JOIN `TestTypeInfoAsTable2` b ON b.`Guid` = a.`TestTypeInfoGuid` AND b.`Name` = 'xxx'", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, b.`Guid`, b.`ParentId`, b.`Name`, a.`Title`, a.`CreateTime` FROM `tb_topicAsTable1` a LEFT JOIN `TestTypeParentInfoAsTable` b__Parent ON 1 = 1 LEFT JOIN `TestTypeInfoAsTable2` b ON b.`Guid` = a.`TestTypeInfoGuid` AND b.`Name` = 'xxx' WHERE (b__Parent.`Id` = 10)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
				
			||||||
 | 
								query = select
 | 
				
			||||||
 | 
									.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid)
 | 
				
			||||||
 | 
									.LeftJoin(a => a.Type.Parent.Id == a.Type.ParentId).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, a__Type.`Guid`, a__Type.`ParentId`, a__Type.`Name`, a.`Title`, a.`CreateTime` FROM `tb_topicAsTable1` a LEFT JOIN `TestTypeInfoAsTable2` a__Type ON a__Type.`Guid` = a.`TestTypeInfoGuid` LEFT JOIN `TestTypeParentInfoAsTable` a__Type__Parent ON a__Type__Parent.`Id` = a__Type.`ParentId`", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select
 | 
				
			||||||
 | 
									.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid)
 | 
				
			||||||
 | 
									.LeftJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, b.`Guid`, b.`ParentId`, b.`Name`, a.`Title`, a.`CreateTime` FROM `tb_topicAsTable1` a LEFT JOIN `TestTypeInfoAsTable2` b ON b.`Guid` = a.`TestTypeInfoGuid` LEFT JOIN `TestTypeParentInfoAsTable` c ON c.`Id` = b.`ParentId`", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
 | 
				
			||||||
 | 
								var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
 | 
				
			||||||
 | 
									 .LeftJoin(a => a.TestTypeInfoGuid == b.Guid)
 | 
				
			||||||
 | 
									 .LeftJoin(a => b.ParentId == c.Id)).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query2.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, b.`Guid`, b.`ParentId`, b.`Name`, a.`Title`, a.`CreateTime` FROM `tb_topicAsTable1` a LEFT JOIN `TestTypeInfoAsTable2` b ON a.`TestTypeInfoGuid` = b.`Guid` LEFT JOIN `TestTypeParentInfoAsTable` c ON b.`ParentId` = c.`Id`", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
 | 
				
			||||||
 | 
								query = select.LeftJoin("TestTypeInfo b on b.Guid = a.TestTypeInfoGuid").AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, a.`Title`, a.`CreateTime` FROM `tb_topicAsTable1` a LEFT JOIN TestTypeInfo b on b.Guid = a.TestTypeInfoGuid", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin("TestTypeInfo b on b.Guid = a.TestTypeInfoGuid and b.Name = ?bname", new { bname = "xxx" }).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TestTypeInfoGuid`, a.`Title`, a.`CreateTime` FROM `tb_topicAsTable1` a LEFT JOIN TestTypeInfo b on b.Guid = a.TestTypeInfoGuid and b.Name = ?bname", sql);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -103,5 +103,14 @@ namespace FreeSql.Tests.MySql {
 | 
				
			|||||||
		public void ExecuteUpdated() {
 | 
							public void ExecuteUpdated() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								Assert.Null(g.mysql.Update<Topic>().ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE `tb_topicAsTable` SET title='test' \r\nWHERE (`Id` = 1 OR `Id` = 2)", g.mysql.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE `tb_topicAsTable` SET title='test1' \r\nWHERE (`Id` = 1)", g.mysql.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE `tb_topicAsTable` SET title='test1' \r\nWHERE (`Id` = 1 OR `Id` = 2)", g.mysql.Update<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE `tb_topicAsTable` SET title='test1' \r\nWHERE (`Id` = 1)", g.mysql.Update<Topic>(new { id = 1 }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -69,5 +69,21 @@ namespace FreeSql.Tests.Oracle {
 | 
				
			|||||||
			//var item = g.oracle.Insert<Topic>(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteInserted();
 | 
								//var item = g.oracle.Insert<Topic>(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteInserted();
 | 
				
			||||||
			//Assert.Equal(item[0].Id, delete.Where(a => a.Id == item[0].Id).ExecuteDeleted()[0].Id);
 | 
								//Assert.Equal(item[0].Id, delete.Where(a => a.Id == item[0].Id).ExecuteDeleted()[0].Id);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								Assert.Null(g.oracle.Delete<Topic>().ToSql());
 | 
				
			||||||
 | 
								var sql = g.oracle.Delete<Topic>(new[] { 1, 2 }).AsTable(a => "TopicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM \"TopicAsTable\" WHERE (\"ID\" = 1 OR \"ID\" = 2)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = g.oracle.Delete<Topic>(new Topic { Id = 1, Title = "test" }).AsTable(a => "TopicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM \"TopicAsTable\" WHERE (\"ID\" = 1)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = g.oracle.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).AsTable(a => "TopicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM \"TopicAsTable\" WHERE (\"ID\" = 1 OR \"ID\" = 2)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = g.oracle.Delete<Topic>(new { id = 1 }).AsTable(a => "TopicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM \"TopicAsTable\" WHERE (\"ID\" = 1)", sql);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -169,5 +169,112 @@ INTO ""TB_TOPIC_INSERT""(""CLICKS"") VALUES(:Clicks9)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			//var items2 = insert.AppendData(items).ExecuteInserted();
 | 
								//var items2 = insert.AppendData(items).ExecuteInserted();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								var items = new List<Topic>();
 | 
				
			||||||
 | 
								for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newTitle{a}", Clicks = a * 100 });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								var sql = insert.AppendData(items.First()).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"CLICKS\", \"TITLE\", \"CREATETIME\") VALUES(:Clicks0, :Title0, :CreateTime0)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal(@"INSERT ALL
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(:Clicks0, :Title0, :CreateTime0)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(:Clicks1, :Title1, :CreateTime1)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(:Clicks2, :Title2, :CreateTime2)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(:Clicks3, :Title3, :CreateTime3)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(:Clicks4, :Title4, :CreateTime4)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(:Clicks5, :Title5, :CreateTime5)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(:Clicks6, :Title6, :CreateTime6)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(:Clicks7, :Title7, :CreateTime7)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(:Clicks8, :Title8, :CreateTime8)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"", ""CREATETIME"") VALUES(:Clicks9, :Title9, :CreateTime9)
 | 
				
			||||||
 | 
					 SELECT 1 FROM DUAL", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal(@"INSERT ALL
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title0)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title1)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title2)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title3)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title4)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title5)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title6)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title7)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title8)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title9)
 | 
				
			||||||
 | 
					 SELECT 1 FROM DUAL", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal(@"INSERT ALL
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks0, :Title0)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks1, :Title1)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks2, :Title2)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks3, :Title3)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks4, :Title4)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks5, :Title5)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks6, :Title6)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks7, :Title7)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks8, :Title8)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks9, :Title9)
 | 
				
			||||||
 | 
					 SELECT 1 FROM DUAL", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal(@"INSERT ALL
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title0)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title1)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title2)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title3)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title4)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title5)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title6)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title7)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title8)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""TITLE"") VALUES(:Title9)
 | 
				
			||||||
 | 
					 SELECT 1 FROM DUAL", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal(@"INSERT ALL
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks0, :Title0)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks1, :Title1)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks2, :Title2)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks3, :Title3)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks4, :Title4)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks5, :Title5)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks6, :Title6)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks7, :Title7)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks8, :Title8)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks9, :Title9)
 | 
				
			||||||
 | 
					 SELECT 1 FROM DUAL", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal(@"INSERT ALL
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks0, :Title0)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks1, :Title1)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks2, :Title2)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks3, :Title3)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks4, :Title4)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks5, :Title5)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks6, :Title6)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks7, :Title7)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks8, :Title8)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"", ""TITLE"") VALUES(:Clicks9, :Title9)
 | 
				
			||||||
 | 
					 SELECT 1 FROM DUAL", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal(@"INSERT ALL
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"") VALUES(:Clicks0)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"") VALUES(:Clicks1)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"") VALUES(:Clicks2)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"") VALUES(:Clicks3)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"") VALUES(:Clicks4)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"") VALUES(:Clicks5)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"") VALUES(:Clicks6)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"") VALUES(:Clicks7)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"") VALUES(:Clicks8)
 | 
				
			||||||
 | 
					INTO ""Topic_InsertAsTable""(""CLICKS"") VALUES(:Clicks9)
 | 
				
			||||||
 | 
					 SELECT 1 FROM DUAL", sql);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -504,5 +504,69 @@ namespace FreeSql.Tests.Oracle {
 | 
				
			|||||||
		[Fact]
 | 
							[Fact]
 | 
				
			||||||
		public void As() {
 | 
							public void As() {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								Func<Type, string, string> tableRule = (type, oldname) => {
 | 
				
			||||||
 | 
									if (type == typeof(Topic)) return oldname + "AsTable1";
 | 
				
			||||||
 | 
									else if (type == typeof(TestTypeInfo)) return oldname + "AsTable2";
 | 
				
			||||||
 | 
									return oldname + "AsTable";
 | 
				
			||||||
 | 
								};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a.Type<70><65>a.Type.Parent <20><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
				
			||||||
 | 
								var query = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid).AsTable(tableRule);
 | 
				
			||||||
 | 
								var sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TESTTYPEINFOGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFOAsTable2\" a__Type ON a__Type.\"GUID\" = a.\"TESTTYPEINFOGUID\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid && a.Type.Name == "xxx").AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TESTTYPEINFOGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFOAsTable2\" a__Type ON a__Type.\"GUID\" = a.\"TESTTYPEINFOGUID\" AND a__Type.\"NAME\" = 'xxx'", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TESTTYPEINFOGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEPARENTINFOAsTable\" a__Type__Parent ON 1 = 1 LEFT JOIN \"TESTTYPEINFOAsTable2\" a__Type ON a__Type.\"GUID\" = a.\"TESTTYPEINFOGUID\" AND a__Type.\"NAME\" = 'xxx' WHERE (a__Type__Parent.\"ID\" = 10)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
				
			||||||
 | 
								query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TESTTYPEINFOGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFOAsTable2\" b ON b.\"GUID\" = a.\"TESTTYPEINFOGUID\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx").AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TESTTYPEINFOGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFOAsTable2\" b ON b.\"GUID\" = a.\"TESTTYPEINFOGUID\" AND b.\"NAME\" = 'xxx'", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TESTTYPEINFOGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEPARENTINFOAsTable\" b__Parent ON 1 = 1 LEFT JOIN \"TESTTYPEINFOAsTable2\" b ON b.\"GUID\" = a.\"TESTTYPEINFOGUID\" AND b.\"NAME\" = 'xxx' WHERE (b__Parent.\"ID\" = 10)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
				
			||||||
 | 
								query = select
 | 
				
			||||||
 | 
									.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid)
 | 
				
			||||||
 | 
									.LeftJoin(a => a.Type.Parent.Id == a.Type.ParentId).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TESTTYPEINFOGUID\", a__Type.\"GUID\", a__Type.\"PARENTID\", a__Type.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFOAsTable2\" a__Type ON a__Type.\"GUID\" = a.\"TESTTYPEINFOGUID\" LEFT JOIN \"TESTTYPEPARENTINFOAsTable\" a__Type__Parent ON a__Type__Parent.\"ID\" = a__Type.\"PARENTID\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select
 | 
				
			||||||
 | 
									.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid)
 | 
				
			||||||
 | 
									.LeftJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TESTTYPEINFOGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFOAsTable2\" b ON b.\"GUID\" = a.\"TESTTYPEINFOGUID\" LEFT JOIN \"TESTTYPEPARENTINFOAsTable\" c ON c.\"ID\" = b.\"PARENTID\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
 | 
				
			||||||
 | 
								var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
 | 
				
			||||||
 | 
									 .LeftJoin(a => a.TestTypeInfoGuid == b.Guid)
 | 
				
			||||||
 | 
									 .LeftJoin(a => b.ParentId == c.Id)).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query2.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TESTTYPEINFOGUID\", b.\"GUID\", b.\"PARENTID\", b.\"NAME\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFOAsTable2\" b ON a.\"TESTTYPEINFOGUID\" = b.\"GUID\" LEFT JOIN \"TESTTYPEPARENTINFOAsTable\" c ON b.\"PARENTID\" = c.\"ID\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
 | 
				
			||||||
 | 
								query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TESTTYPEINFOGUID\"").AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TESTTYPEINFOGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TESTTYPEINFOGUID\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin("\"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TESTTYPEINFOGUID\" and b.\"NAME\" = :bname", new { bname = "xxx" }).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TESTTYPEINFOGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22AsTable1\" a LEFT JOIN \"TESTTYPEINFO\" b on b.\"GUID\" = a.\"TESTTYPEINFOGUID\" and b.\"NAME\" = :bname", sql);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -103,5 +103,14 @@ namespace FreeSql.Tests.Oracle {
 | 
				
			|||||||
		public void ExecuteUpdated() {
 | 
							public void ExecuteUpdated() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								Assert.Null(g.oracle.Update<Topic>().ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE \"tb_topicAsTable\" SET title='test' \r\nWHERE (\"ID\" = 1 OR \"ID\" = 2)", g.oracle.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE \"tb_topicAsTable\" SET title='test1' \r\nWHERE (\"ID\" = 1)", g.oracle.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE \"tb_topicAsTable\" SET title='test1' \r\nWHERE (\"ID\" = 1 OR \"ID\" = 2)", g.oracle.Update<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE \"tb_topicAsTable\" SET title='test1' \r\nWHERE (\"ID\" = 1)", g.oracle.Update<Topic>(new { id = 1 }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,11 +33,12 @@ namespace FreeSql.Tests.Oracle {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		[Fact]
 | 
							[Fact]
 | 
				
			||||||
		public void Query() {
 | 
							public void Query() {
 | 
				
			||||||
			var t3 = g.oracle.Ado.Query<xxx>("select * from \"song\"");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			var t4 = g.oracle.Ado.Query<(int, string, string)>("select * from \"song\"");
 | 
								var t3 = g.oracle.Ado.Query<xxx>("select * from \"TB_TOPIC\"");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			var t5 = g.oracle.Ado.Query<dynamic>("select * from \"song\"");
 | 
								var t4 = g.oracle.Ado.Query<(int, string, string)>("select * from \"TB_TOPIC\"");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								var t5 = g.oracle.Ado.Query<dynamic>("select * from \"TB_TOPIC\"");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		class xxx {
 | 
							class xxx {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,7 +27,7 @@ namespace FreeSql.Tests.OracleExpression {
 | 
				
			|||||||
			public string Name { get; set; }
 | 
								public string Name { get; set; }
 | 
				
			||||||
			public DateTime Time { get; set; }
 | 
								public DateTime Time { get; set; }
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		[Table(Name = "TestTypeParentInfo23123")]
 | 
							[Table(Name = "TestTypeParentInf1")]
 | 
				
			||||||
		class TestTypeParentInfo {
 | 
							class TestTypeParentInfo {
 | 
				
			||||||
			public int Id { get; set; }
 | 
								public int Id { get; set; }
 | 
				
			||||||
			public string Name { get; set; }
 | 
								public string Name { get; set; }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -68,5 +68,21 @@ namespace FreeSql.Tests.PostgreSQL {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			delete.Where(a => a.Id > 0).ExecuteDeleted();
 | 
								delete.Where(a => a.Id > 0).ExecuteDeleted();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								Assert.Null(g.pgsql.Delete<Topic>().ToSql());
 | 
				
			||||||
 | 
								var sql = g.pgsql.Delete<Topic>(new[] { 1, 2 }).AsTable(a => "TopicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM \"TopicAsTable\" WHERE (\"id\" = 1 OR \"id\" = 2)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = g.pgsql.Delete<Topic>(new Topic { Id = 1, Title = "test" }).AsTable(a => "TopicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM \"TopicAsTable\" WHERE (\"id\" = 1)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = g.pgsql.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).AsTable(a => "TopicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM \"TopicAsTable\" WHERE (\"id\" = 1 OR \"id\" = 2)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = g.pgsql.Delete<Topic>(new { id = 1 }).AsTable(a => "TopicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM \"TopicAsTable\" WHERE (\"id\" = 1)", sql);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -81,5 +81,35 @@ namespace FreeSql.Tests.PostgreSQL {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			insert.AppendData(items.First()).ExecuteInserted();
 | 
								insert.AppendData(items.First()).ExecuteInserted();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								var items = new List<Topic>();
 | 
				
			||||||
 | 
								for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newTitle{a}", Clicks = a * 100 });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								var sql = insert.AppendData(items.First()).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"clicks\", \"title\", \"createtime\") VALUES(@clicks0, @title0, @createtime0)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"clicks\", \"title\", \"createtime\") VALUES(@clicks0, @title0, @createtime0), (@clicks1, @title1, @createtime1), (@clicks2, @title2, @createtime2), (@clicks3, @title3, @createtime3), (@clicks4, @title4, @createtime4), (@clicks5, @title5, @createtime5), (@clicks6, @title6, @createtime6), (@clicks7, @title7, @createtime7), (@clicks8, @title8, @createtime8), (@clicks9, @title9, @createtime9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"title\") VALUES(@title0), (@title1), (@title2), (@title3), (@title4), (@title5), (@title6), (@title7), (@title8), (@title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"clicks\", \"title\") VALUES(@clicks0, @title0), (@clicks1, @title1), (@clicks2, @title2), (@clicks3, @title3), (@clicks4, @title4), (@clicks5, @title5), (@clicks6, @title6), (@clicks7, @title7), (@clicks8, @title8), (@clicks9, @title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"title\") VALUES(@title0), (@title1), (@title2), (@title3), (@title4), (@title5), (@title6), (@title7), (@title8), (@title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"clicks\", \"title\") VALUES(@clicks0, @title0), (@clicks1, @title1), (@clicks2, @title2), (@clicks3, @title3), (@clicks4, @title4), (@clicks5, @title5), (@clicks6, @title6), (@clicks7, @title7), (@clicks8, @title8), (@clicks9, @title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"clicks\", \"title\") VALUES(@clicks0, @title0), (@clicks1, @title1), (@clicks2, @title2), (@clicks3, @title3), (@clicks4, @title4), (@clicks5, @title5), (@clicks6, @title6), (@clicks7, @title7), (@clicks8, @title8), (@clicks9, @title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"clicks\") VALUES(@clicks0), (@clicks1), (@clicks2), (@clicks3), (@clicks4), (@clicks5), (@clicks6), (@clicks7), (@clicks8), (@clicks9)", sql);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -581,5 +581,69 @@ namespace FreeSql.Tests.PostgreSQL {
 | 
				
			|||||||
		[Fact]
 | 
							[Fact]
 | 
				
			||||||
		public void As() {
 | 
							public void As() {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								Func<Type, string, string> tableRule = (type, oldname) => {
 | 
				
			||||||
 | 
									if (type == typeof(Topic)) return oldname + "AsTable1";
 | 
				
			||||||
 | 
									else if (type == typeof(TestTypeInfo)) return oldname + "AsTable2";
 | 
				
			||||||
 | 
									return oldname + "AsTable";
 | 
				
			||||||
 | 
								};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a.Type<70><65>a.Type.Parent <20><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
				
			||||||
 | 
								var query = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid).AsTable(tableRule);
 | 
				
			||||||
 | 
								var sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"testtypeinfoguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" a__Type ON a__Type.\"guid\" = a.\"testtypeinfoguid\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid && a.Type.Name == "xxx").AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"testtypeinfoguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" a__Type ON a__Type.\"guid\" = a.\"testtypeinfoguid\" AND a__Type.\"name\" = 'xxx'", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"testtypeinfoguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeparentinfoAsTable\" a__Type__Parent ON 1 = 1 LEFT JOIN \"testtypeinfoAsTable2\" a__Type ON a__Type.\"guid\" = a.\"testtypeinfoguid\" AND a__Type.\"name\" = 'xxx' WHERE (a__Type__Parent.\"id\" = 10)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
				
			||||||
 | 
								query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"testtypeinfoguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" b ON b.\"guid\" = a.\"testtypeinfoguid\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx").AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"testtypeinfoguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" b ON b.\"guid\" = a.\"testtypeinfoguid\" AND b.\"name\" = 'xxx'", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"testtypeinfoguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeparentinfoAsTable\" b__Parent ON 1 = 1 LEFT JOIN \"testtypeinfoAsTable2\" b ON b.\"guid\" = a.\"testtypeinfoguid\" AND b.\"name\" = 'xxx' WHERE (b__Parent.\"id\" = 10)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
				
			||||||
 | 
								query = select
 | 
				
			||||||
 | 
									.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid)
 | 
				
			||||||
 | 
									.LeftJoin(a => a.Type.Parent.Id == a.Type.ParentId).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"testtypeinfoguid\", a__Type.\"guid\", a__Type.\"parentid\", a__Type.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" a__Type ON a__Type.\"guid\" = a.\"testtypeinfoguid\" LEFT JOIN \"testtypeparentinfoAsTable\" a__Type__Parent ON a__Type__Parent.\"id\" = a__Type.\"parentid\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select
 | 
				
			||||||
 | 
									.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid)
 | 
				
			||||||
 | 
									.LeftJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"testtypeinfoguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" b ON b.\"guid\" = a.\"testtypeinfoguid\" LEFT JOIN \"testtypeparentinfoAsTable\" c ON c.\"id\" = b.\"parentid\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
 | 
				
			||||||
 | 
								var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
 | 
				
			||||||
 | 
									 .LeftJoin(a => a.TestTypeInfoGuid == b.Guid)
 | 
				
			||||||
 | 
									 .LeftJoin(a => b.ParentId == c.Id)).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query2.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"testtypeinfoguid\", b.\"guid\", b.\"parentid\", b.\"name\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfoAsTable2\" b ON a.\"testtypeinfoguid\" = b.\"guid\" LEFT JOIN \"testtypeparentinfoAsTable\" c ON b.\"parentid\" = c.\"id\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
 | 
				
			||||||
 | 
								query = select.LeftJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"testtypeinfoguid\"").AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"testtypeinfoguid\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"testtypeinfoguid\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin("\"testtypeinfo\" b on b.\"guid\" = a.\"testtypeinfoguid\" and b.\"name\" = @bname", new { bname = "xxx" }).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"testtypeinfoguid\", a.\"title\", a.\"createtime\" FROM \"tb_topicAsTable1\" a LEFT JOIN \"testtypeinfo\" b on b.\"guid\" = a.\"testtypeinfoguid\" and b.\"name\" = @bname", sql);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -103,5 +103,14 @@ namespace FreeSql.Tests.PostgreSQL {
 | 
				
			|||||||
		public void ExecuteUpdated() {
 | 
							public void ExecuteUpdated() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								Assert.Null(g.pgsql.Update<Topic>().ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE \"tb_topicAsTable\" SET title='test' \r\nWHERE (\"id\" = 1 OR \"id\" = 2)", g.pgsql.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE \"tb_topicAsTable\" SET title='test1' \r\nWHERE (\"id\" = 1)", g.pgsql.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE \"tb_topicAsTable\" SET title='test1' \r\nWHERE (\"id\" = 1 OR \"id\" = 2)", g.pgsql.Update<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE \"tb_topicAsTable\" SET title='test1' \r\nWHERE (\"id\" = 1)", g.pgsql.Update<Topic>(new { id = 1 }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -69,5 +69,21 @@ namespace FreeSql.Tests.SqlServer {
 | 
				
			|||||||
			var item = g.sqlserver.Insert<Topic>(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteInserted();
 | 
								var item = g.sqlserver.Insert<Topic>(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteInserted();
 | 
				
			||||||
			Assert.Equal(item[0].Id, delete.Where(a => a.Id == item[0].Id).ExecuteDeleted()[0].Id);
 | 
								Assert.Equal(item[0].Id, delete.Where(a => a.Id == item[0].Id).ExecuteDeleted()[0].Id);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								Assert.Null(g.sqlserver.Delete<Topic>().ToSql());
 | 
				
			||||||
 | 
								var sql = g.sqlserver.Delete<Topic>(new[] { 1, 2 }).AsTable(a => "tb_topic22211AsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM [tb_topic22211AsTable] WHERE ([Id] = 1 OR [Id] = 2)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = g.sqlserver.Delete<Topic>(new Topic { Id = 1, Title = "test" }).AsTable(a => "tb_topic22211AsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM [tb_topic22211AsTable] WHERE ([Id] = 1)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = g.sqlserver.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).AsTable(a => "tb_topic22211AsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM [tb_topic22211AsTable] WHERE ([Id] = 1 OR [Id] = 2)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = g.sqlserver.Delete<Topic>(new { id = 1 }).AsTable(a => "tb_topic22211AsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM [tb_topic22211AsTable] WHERE ([Id] = 1)", sql);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -81,5 +81,35 @@ namespace FreeSql.Tests.SqlServer {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			var items2 = insert.AppendData(items).ExecuteInserted();
 | 
								var items2 = insert.AppendData(items).ExecuteInserted();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								var items = new List<Topic>();
 | 
				
			||||||
 | 
								for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100, CreateTime = DateTime.Now });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								var sql = insert.AppendData(items.First()).AsTable(a => "tb_topicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks], [Title], [CreateTime]) VALUES(@Clicks0, @Title0, @CreateTime0)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).AsTable(a => "tb_topicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks], [Title], [CreateTime]) VALUES(@Clicks0, @Title0, @CreateTime0), (@Clicks1, @Title1, @CreateTime1), (@Clicks2, @Title2, @CreateTime2), (@Clicks3, @Title3, @CreateTime3), (@Clicks4, @Title4, @CreateTime4), (@Clicks5, @Title5, @CreateTime5), (@Clicks6, @Title6, @CreateTime6), (@Clicks7, @Title7, @CreateTime7), (@Clicks8, @Title8, @CreateTime8), (@Clicks9, @Title9, @CreateTime9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "tb_topicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO [tb_topicAsTable]([Title]) VALUES(@Title0), (@Title1), (@Title2), (@Title3), (@Title4), (@Title5), (@Title6), (@Title7), (@Title8), (@Title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "tb_topicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks], [Title]) VALUES(@Clicks0, @Title0), (@Clicks1, @Title1), (@Clicks2, @Title2), (@Clicks3, @Title3), (@Clicks4, @Title4), (@Clicks5, @Title5), (@Clicks6, @Title6), (@Clicks7, @Title7), (@Clicks8, @Title8), (@Clicks9, @Title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "tb_topicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO [tb_topicAsTable]([Title]) VALUES(@Title0), (@Title1), (@Title2), (@Title3), (@Title4), (@Title5), (@Title6), (@Title7), (@Title8), (@Title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).AsTable(a => "tb_topicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks], [Title]) VALUES(@Clicks0, @Title0), (@Clicks1, @Title1), (@Clicks2, @Title2), (@Clicks3, @Title3), (@Clicks4, @Title4), (@Clicks5, @Title5), (@Clicks6, @Title6), (@Clicks7, @Title7), (@Clicks8, @Title8), (@Clicks9, @Title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "tb_topicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks], [Title]) VALUES(@Clicks0, @Title0), (@Clicks1, @Title1), (@Clicks2, @Title2), (@Clicks3, @Title3), (@Clicks4, @Title4), (@Clicks5, @Title5), (@Clicks6, @Title6), (@Clicks7, @Title7), (@Clicks8, @Title8), (@Clicks9, @Title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).AsTable(a => "tb_topicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO [tb_topicAsTable]([Clicks]) VALUES(@Clicks0), (@Clicks1), (@Clicks2), (@Clicks3), (@Clicks4), (@Clicks5), (@Clicks6), (@Clicks7), (@Clicks8), (@Clicks9)", sql);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -504,5 +504,69 @@ namespace FreeSql.Tests.SqlServer {
 | 
				
			|||||||
		[Fact]
 | 
							[Fact]
 | 
				
			||||||
		public void As() {
 | 
							public void As() {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								Func<Type, string, string> tableRule = (type, oldname) => {
 | 
				
			||||||
 | 
									if (type == typeof(Topic)) return oldname + "AsTable1";
 | 
				
			||||||
 | 
									else if (type == typeof(TestTypeInfo)) return oldname + "AsTable2";
 | 
				
			||||||
 | 
									return oldname + "AsTable";
 | 
				
			||||||
 | 
								};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a.Type<70><65>a.Type.Parent <20><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
				
			||||||
 | 
								var query = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid).AsTable(tableRule);
 | 
				
			||||||
 | 
								var sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TestTypeInfoGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN [TestTypeInfoAsTable2] a__Type ON a__Type.[Guid] = a.[TestTypeInfoGuid]", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid && a.Type.Name == "xxx").AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TestTypeInfoGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN [TestTypeInfoAsTable2] a__Type ON a__Type.[Guid] = a.[TestTypeInfoGuid] AND a__Type.[Name] = 'xxx'", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TestTypeInfoGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN [TestTypeParentInfoAsTable] a__Type__Parent ON 1 = 1 LEFT JOIN [TestTypeInfoAsTable2] a__Type ON a__Type.[Guid] = a.[TestTypeInfoGuid] AND a__Type.[Name] = 'xxx' WHERE (a__Type__Parent.[Id] = 10)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
				
			||||||
 | 
								query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TestTypeInfoGuid], b.[Guid], b.[ParentId], b.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN [TestTypeInfoAsTable2] b ON b.[Guid] = a.[TestTypeInfoGuid]", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx").AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TestTypeInfoGuid], b.[Guid], b.[ParentId], b.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN [TestTypeInfoAsTable2] b ON b.[Guid] = a.[TestTypeInfoGuid] AND b.[Name] = 'xxx'", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TestTypeInfoGuid], b.[Guid], b.[ParentId], b.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN [TestTypeParentInfoAsTable] b__Parent ON 1 = 1 LEFT JOIN [TestTypeInfoAsTable2] b ON b.[Guid] = a.[TestTypeInfoGuid] AND b.[Name] = 'xxx' WHERE (b__Parent.[Id] = 10)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
				
			||||||
 | 
								query = select
 | 
				
			||||||
 | 
									.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid)
 | 
				
			||||||
 | 
									.LeftJoin(a => a.Type.Parent.Id == a.Type.ParentId).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TestTypeInfoGuid], a__Type.[Guid], a__Type.[ParentId], a__Type.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN [TestTypeInfoAsTable2] a__Type ON a__Type.[Guid] = a.[TestTypeInfoGuid] LEFT JOIN [TestTypeParentInfoAsTable] a__Type__Parent ON a__Type__Parent.[Id] = a__Type.[ParentId]", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select
 | 
				
			||||||
 | 
									.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid)
 | 
				
			||||||
 | 
									.LeftJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TestTypeInfoGuid], b.[Guid], b.[ParentId], b.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN [TestTypeInfoAsTable2] b ON b.[Guid] = a.[TestTypeInfoGuid] LEFT JOIN [TestTypeParentInfoAsTable] c ON c.[Id] = b.[ParentId]", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
 | 
				
			||||||
 | 
								var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
 | 
				
			||||||
 | 
									 .LeftJoin(a => a.TestTypeInfoGuid == b.Guid)
 | 
				
			||||||
 | 
									 .LeftJoin(a => b.ParentId == c.Id)).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query2.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TestTypeInfoGuid], b.[Guid], b.[ParentId], b.[Name], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN [TestTypeInfoAsTable2] b ON a.[TestTypeInfoGuid] = b.[Guid] LEFT JOIN [TestTypeParentInfoAsTable] c ON b.[ParentId] = c.[Id]", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
 | 
				
			||||||
 | 
								query = select.LeftJoin("[TestTypeInfo] b on b.[Guid] = a.[TestTypeInfoGuid]").AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TestTypeInfoGuid], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN [TestTypeInfo] b on b.[Guid] = a.[TestTypeInfoGuid]", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin("[TestTypeInfo] b on b.[Guid] = a.[TestTypeInfoGuid] and b.[Name] = @bname", new { bname = "xxx" }).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TestTypeInfoGuid], a.[Title], a.[CreateTime] FROM [tb_topic22AsTable1] a LEFT JOIN [TestTypeInfo] b on b.[Guid] = a.[TestTypeInfoGuid] and b.[Name] = @bname", sql);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -103,5 +103,14 @@ namespace FreeSql.Tests.SqlServer {
 | 
				
			|||||||
		public void ExecuteUpdated() {
 | 
							public void ExecuteUpdated() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								Assert.Null(g.sqlserver.Update<Topic>().ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE [tb_topicAsTable] SET title='test' \r\nWHERE ([Id] = 1 OR [Id] = 2)", g.sqlserver.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE [tb_topicAsTable] SET title='test1' \r\nWHERE ([Id] = 1)", g.sqlserver.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE [tb_topicAsTable] SET title='test1' \r\nWHERE ([Id] = 1 OR [Id] = 2)", g.sqlserver.Update<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE [tb_topicAsTable] SET title='test1' \r\nWHERE ([Id] = 1)", g.sqlserver.Update<Topic>(new { id = 1 }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -69,5 +69,21 @@ namespace FreeSql.Tests.Sqlite {
 | 
				
			|||||||
			//var item = g.Sqlite.Insert<Topic>(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteInserted();
 | 
								//var item = g.Sqlite.Insert<Topic>(new Topic { Title = "xxxx", CreateTime = DateTime.Now }).ExecuteInserted();
 | 
				
			||||||
			//Assert.Equal(item[0].Id, delete.Where(a => a.Id == item[0].Id).ExecuteDeleted()[0].Id);
 | 
								//Assert.Equal(item[0].Id, delete.Where(a => a.Id == item[0].Id).ExecuteDeleted()[0].Id);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								Assert.Null(g.sqlite.Delete<Topic>().AsTable(a => "TopicAsTable").ToSql());
 | 
				
			||||||
 | 
								var sql = g.sqlite.Delete<Topic>(new[] { 1, 2 }).AsTable(a => "TopicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM \"TopicAsTable\" WHERE (\"Id\" = 1 OR \"Id\" = 2)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = g.sqlite.Delete<Topic>(new Topic { Id = 1, Title = "test" }).AsTable(a => "TopicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM \"TopicAsTable\" WHERE (\"Id\" = 1)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = g.sqlite.Delete<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).AsTable(a => "TopicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM \"TopicAsTable\" WHERE (\"Id\" = 1 OR \"Id\" = 2)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = g.sqlite.Delete<Topic>(new { id = 1 }).AsTable(a => "TopicAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("DELETE FROM \"TopicAsTable\" WHERE (\"Id\" = 1)", sql);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -77,5 +77,35 @@ namespace FreeSql.Tests.Sqlite {
 | 
				
			|||||||
		[Fact]
 | 
							[Fact]
 | 
				
			||||||
		public void ExecuteInserted() {
 | 
							public void ExecuteInserted() {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								var items = new List<Topic>();
 | 
				
			||||||
 | 
								for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newTitle{a}", Clicks = a * 100 });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								var sql = insert.AppendData(items.First()).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"Clicks\", \"Title\", \"CreateTime\") VALUES(@Clicks0, @Title0, @CreateTime0)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"Clicks\", \"Title\", \"CreateTime\") VALUES(@Clicks0, @Title0, @CreateTime0), (@Clicks1, @Title1, @CreateTime1), (@Clicks2, @Title2, @CreateTime2), (@Clicks3, @Title3, @CreateTime3), (@Clicks4, @Title4, @CreateTime4), (@Clicks5, @Title5, @CreateTime5), (@Clicks6, @Title6, @CreateTime6), (@Clicks7, @Title7, @CreateTime7), (@Clicks8, @Title8, @CreateTime8), (@Clicks9, @Title9, @CreateTime9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"Title\") VALUES(@Title0), (@Title1), (@Title2), (@Title3), (@Title4), (@Title5), (@Title6), (@Title7), (@Title8), (@Title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"Clicks\", \"Title\") VALUES(@Clicks0, @Title0), (@Clicks1, @Title1), (@Clicks2, @Title2), (@Clicks3, @Title3), (@Clicks4, @Title4), (@Clicks5, @Title5), (@Clicks6, @Title6), (@Clicks7, @Title7), (@Clicks8, @Title8), (@Clicks9, @Title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).InsertColumns(a => a.Title).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"Title\") VALUES(@Title0), (@Title1), (@Title2), (@Title3), (@Title4), (@Title5), (@Title6), (@Title7), (@Title8), (@Title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).InsertColumns(a => new { a.Title, a.Clicks }).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"Clicks\", \"Title\") VALUES(@Clicks0, @Title0), (@Clicks1, @Title1), (@Clicks2, @Title2), (@Clicks3, @Title3), (@Clicks4, @Title4), (@Clicks5, @Title5), (@Clicks6, @Title6), (@Clicks7, @Title7), (@Clicks8, @Title8), (@Clicks9, @Title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).IgnoreColumns(a => a.CreateTime).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"Clicks\", \"Title\") VALUES(@Clicks0, @Title0), (@Clicks1, @Title1), (@Clicks2, @Title2), (@Clicks3, @Title3), (@Clicks4, @Title4), (@Clicks5, @Title5), (@Clicks6, @Title6), (@Clicks7, @Title7), (@Clicks8, @Title8), (@Clicks9, @Title9)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sql = insert.AppendData(items).IgnoreColumns(a => new { a.Title, a.CreateTime }).AsTable(a => "Topic_InsertAsTable").ToSql();
 | 
				
			||||||
 | 
								Assert.Equal("INSERT INTO \"Topic_InsertAsTable\"(\"Clicks\") VALUES(@Clicks0), (@Clicks1), (@Clicks2), (@Clicks3), (@Clicks4), (@Clicks5), (@Clicks6), (@Clicks7), (@Clicks8), (@Clicks9)", sql);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -545,5 +545,69 @@ namespace FreeSql.Tests.Sqlite {
 | 
				
			|||||||
		[Fact]
 | 
							[Fact]
 | 
				
			||||||
		public void As() {
 | 
							public void As() {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								Func<Type, string, string> tableRule = (type, oldname) => {
 | 
				
			||||||
 | 
									if (type == typeof(Topic)) return oldname + "AsTable1";
 | 
				
			||||||
 | 
									else if (type == typeof(TestTypeInfo)) return oldname + "AsTable2";
 | 
				
			||||||
 | 
									return oldname + "AsTable";
 | 
				
			||||||
 | 
								};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a.Type<70><65>a.Type.Parent <20><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
				
			||||||
 | 
								var query = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid).AsTable(tableRule);
 | 
				
			||||||
 | 
								var sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22AsTable1\" a LEFT JOIN \"TestTypeInfoAsTable2\" a__Type ON a__Type.\"Guid\" = a.\"TestTypeInfoGuid\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid && a.Type.Name == "xxx").AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22AsTable1\" a LEFT JOIN \"TestTypeInfoAsTable2\" a__Type ON a__Type.\"Guid\" = a.\"TestTypeInfoGuid\" AND a__Type.\"Name\" = 'xxx'", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid && a.Type.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22AsTable1\" a LEFT JOIN \"TestTypeParentInfoAsTable\" a__Type__Parent ON 1 = 1 LEFT JOIN \"TestTypeInfoAsTable2\" a__Type ON a__Type.\"Guid\" = a.\"TestTypeInfoGuid\" AND a__Type.\"Name\" = 'xxx' WHERE (a__Type__Parent.\"Id\" = 10)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
				
			||||||
 | 
								query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22AsTable1\" a LEFT JOIN \"TestTypeInfoAsTable2\" b ON b.\"Guid\" = a.\"TestTypeInfoGuid\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx").AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22AsTable1\" a LEFT JOIN \"TestTypeInfoAsTable2\" b ON b.\"Guid\" = a.\"TestTypeInfoGuid\" AND b.\"Name\" = 'xxx'", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid && b.Name == "xxx").Where(a => a.Type.Parent.Id == 10).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22AsTable1\" a LEFT JOIN \"TestTypeParentInfoAsTable\" b__Parent ON 1 = 1 LEFT JOIN \"TestTypeInfoAsTable2\" b ON b.\"Guid\" = a.\"TestTypeInfoGuid\" AND b.\"Name\" = 'xxx' WHERE (b__Parent.\"Id\" = 10)", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
				
			||||||
 | 
								query = select
 | 
				
			||||||
 | 
									.LeftJoin(a => a.Type.Guid == a.TestTypeInfoGuid)
 | 
				
			||||||
 | 
									.LeftJoin(a => a.Type.Parent.Id == a.Type.ParentId).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a__Type.\"Guid\", a__Type.\"ParentId\", a__Type.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22AsTable1\" a LEFT JOIN \"TestTypeInfoAsTable2\" a__Type ON a__Type.\"Guid\" = a.\"TestTypeInfoGuid\" LEFT JOIN \"TestTypeParentInfoAsTable\" a__Type__Parent ON a__Type__Parent.\"Id\" = a__Type.\"ParentId\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select
 | 
				
			||||||
 | 
									.LeftJoin<TestTypeInfo>((a, b) => b.Guid == a.TestTypeInfoGuid)
 | 
				
			||||||
 | 
									.LeftJoin<TestTypeParentInfo>((a, c) => c.Id == a.Type.ParentId).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22AsTable1\" a LEFT JOIN \"TestTypeInfoAsTable2\" b ON b.\"Guid\" = a.\"TestTypeInfoGuid\" LEFT JOIN \"TestTypeParentInfoAsTable\" c ON c.\"Id\" = b.\"ParentId\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b<EFBFBD><62>c<EFBFBD><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ
 | 
				
			||||||
 | 
								var query2 = select.From<TestTypeInfo, TestTypeParentInfo>((s, b, c) => s
 | 
				
			||||||
 | 
									 .LeftJoin(a => a.TestTypeInfoGuid == b.Guid)
 | 
				
			||||||
 | 
									 .LeftJoin(a => b.ParentId == c.Id)).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query2.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", b.\"Guid\", b.\"ParentId\", b.\"Name\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22AsTable1\" a LEFT JOIN \"TestTypeInfoAsTable2\" b ON a.\"TestTypeInfoGuid\" = b.\"Guid\" LEFT JOIN \"TestTypeParentInfoAsTable\" c ON b.\"ParentId\" = c.\"Id\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB>
 | 
				
			||||||
 | 
								query = select.LeftJoin("\"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\"").AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22AsTable1\" a LEFT JOIN \"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\"", sql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								query = select.LeftJoin("\"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\" and b.\"Name\" = @bname", new { bname = "xxx" }).AsTable(tableRule);
 | 
				
			||||||
 | 
								sql = query.ToSql().Replace("\r\n", "");
 | 
				
			||||||
 | 
								Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TestTypeInfoGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22AsTable1\" a LEFT JOIN \"TestTypeInfo\" b on b.\"Guid\" = a.\"TestTypeInfoGuid\" and b.\"Name\" = @bname", sql);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -103,5 +103,14 @@ namespace FreeSql.Tests.Sqlite {
 | 
				
			|||||||
		public void ExecuteUpdated() {
 | 
							public void ExecuteUpdated() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Fact]
 | 
				
			||||||
 | 
							public void AsTable() {
 | 
				
			||||||
 | 
								Assert.Null(g.sqlite.Update<Topic>().ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE \"tb_topicAsTable\" SET title='test' \r\nWHERE (\"Id\" = 1 OR \"Id\" = 2)", g.sqlite.Update<Topic>(new[] { 1, 2 }).SetRaw("title='test'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE \"tb_topicAsTable\" SET title='test1' \r\nWHERE (\"Id\" = 1)", g.sqlite.Update<Topic>(new Topic { Id = 1, Title = "test" }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE \"tb_topicAsTable\" SET title='test1' \r\nWHERE (\"Id\" = 1 OR \"Id\" = 2)", g.sqlite.Update<Topic>(new[] { new Topic { Id = 1, Title = "test" }, new Topic { Id = 2, Title = "test" } }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
								Assert.Equal("UPDATE \"tb_topicAsTable\" SET title='test1' \r\nWHERE (\"Id\" = 1)", g.sqlite.Update<Topic>(new { id = 1 }).SetRaw("title='test1'").AsTable(a => "tb_topicAsTable").ToSql());
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,6 +39,12 @@ namespace FreeSql {
 | 
				
			|||||||
		/// <returns></returns>
 | 
							/// <returns></returns>
 | 
				
			||||||
		IDelete<T1> WhereExists<TEntity2>(ISelect<TEntity2> select, bool notExists = false) where TEntity2 : class;
 | 
							IDelete<T1> WhereExists<TEntity2>(ISelect<TEntity2> select, bool notExists = false) where TEntity2 : class;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/// <summary>
 | 
				
			||||||
 | 
							/// 设置表名规则,可用于分库/分表,参数1:默认表名;返回值:新表名;
 | 
				
			||||||
 | 
							/// </summary>
 | 
				
			||||||
 | 
							/// <param name="dataTable"></param>
 | 
				
			||||||
 | 
							/// <returns></returns>
 | 
				
			||||||
 | 
							IDelete<T1> AsTable(Func<string, string> tableRule);
 | 
				
			||||||
		/// <summary>
 | 
							/// <summary>
 | 
				
			||||||
		/// 返回即将执行的SQL语句
 | 
							/// 返回即将执行的SQL语句
 | 
				
			||||||
		/// </summary>
 | 
							/// </summary>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,6 +32,12 @@ namespace FreeSql {
 | 
				
			|||||||
		/// <returns></returns>
 | 
							/// <returns></returns>
 | 
				
			||||||
		IInsert<T1> IgnoreColumns(Expression<Func<T1, object>> columns);
 | 
							IInsert<T1> IgnoreColumns(Expression<Func<T1, object>> columns);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/// <summary>
 | 
				
			||||||
 | 
							/// 设置表名规则,可用于分库/分表,参数1:默认表名;返回值:新表名;
 | 
				
			||||||
 | 
							/// </summary>
 | 
				
			||||||
 | 
							/// <param name="dataTable"></param>
 | 
				
			||||||
 | 
							/// <returns></returns>
 | 
				
			||||||
 | 
							IInsert<T1> AsTable(Func<string, string> tableRule);
 | 
				
			||||||
		/// <summary>
 | 
							/// <summary>
 | 
				
			||||||
		/// 返回即将执行的SQL语句
 | 
							/// 返回即将执行的SQL语句
 | 
				
			||||||
		/// </summary>
 | 
							/// </summary>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,6 +35,12 @@ namespace FreeSql {
 | 
				
			|||||||
		T1 First();
 | 
							T1 First();
 | 
				
			||||||
		Task<T1> FirstAsync();
 | 
							Task<T1> FirstAsync();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/// <summary>
 | 
				
			||||||
 | 
							/// 设置表名规则,可用于分库/分表,参数1:实体类型;参数2:默认表名;返回值:新表名;
 | 
				
			||||||
 | 
							/// </summary>
 | 
				
			||||||
 | 
							/// <param name="dataTable"></param>
 | 
				
			||||||
 | 
							/// <returns></returns>
 | 
				
			||||||
 | 
							TSelect AsTable(Func<Type, string, string> tableRule);
 | 
				
			||||||
		/// <summary>
 | 
							/// <summary>
 | 
				
			||||||
		/// 返回即将执行的SQL语句
 | 
							/// 返回即将执行的SQL语句
 | 
				
			||||||
		/// </summary>
 | 
							/// </summary>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -82,6 +82,12 @@ namespace FreeSql {
 | 
				
			|||||||
		/// <returns></returns>
 | 
							/// <returns></returns>
 | 
				
			||||||
		IUpdate<T1> WhereExists<TEntity2>(ISelect<TEntity2> select, bool notExists = false) where TEntity2 : class;
 | 
							IUpdate<T1> WhereExists<TEntity2>(ISelect<TEntity2> select, bool notExists = false) where TEntity2 : class;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/// <summary>
 | 
				
			||||||
 | 
							/// 设置表名规则,可用于分库/分表,参数1:默认表名;返回值:新表名;
 | 
				
			||||||
 | 
							/// </summary>
 | 
				
			||||||
 | 
							/// <param name="dataTable"></param>
 | 
				
			||||||
 | 
							/// <returns></returns>
 | 
				
			||||||
 | 
							IUpdate<T1> AsTable(Func<string, string> tableRule);
 | 
				
			||||||
		/// <summary>
 | 
							/// <summary>
 | 
				
			||||||
		/// 返回即将执行的SQL语句
 | 
							/// 返回即将执行的SQL语句
 | 
				
			||||||
		/// </summary>
 | 
							/// </summary>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,6 +15,7 @@ namespace FreeSql.Internal.CommonProvider {
 | 
				
			|||||||
		protected CommonExpression _commonExpression;
 | 
							protected CommonExpression _commonExpression;
 | 
				
			||||||
		protected List<T1> _source = new List<T1>();
 | 
							protected List<T1> _source = new List<T1>();
 | 
				
			||||||
		protected TableInfo _table;
 | 
							protected TableInfo _table;
 | 
				
			||||||
 | 
							protected Func<string, string> _tableRule;
 | 
				
			||||||
		protected StringBuilder _where = new StringBuilder();
 | 
							protected StringBuilder _where = new StringBuilder();
 | 
				
			||||||
		protected int _whereTimes = 0;
 | 
							protected int _whereTimes = 0;
 | 
				
			||||||
		protected List<DbParameter> _params = new List<DbParameter>();
 | 
							protected List<DbParameter> _params = new List<DbParameter>();
 | 
				
			||||||
@@ -24,7 +25,6 @@ namespace FreeSql.Internal.CommonProvider {
 | 
				
			|||||||
			_commonUtils = commonUtils;
 | 
								_commonUtils = commonUtils;
 | 
				
			||||||
			_commonExpression = commonExpression;
 | 
								_commonExpression = commonExpression;
 | 
				
			||||||
			_table = _commonUtils.GetTableByEntity(typeof(T1));
 | 
								_table = _commonUtils.GetTableByEntity(typeof(T1));
 | 
				
			||||||
			_where.Append("DELETE FROM ").Append(_commonUtils.QuoteSqlName(_table.DbName)).Append(" WHERE ");
 | 
					 | 
				
			||||||
			this.Where(_commonUtils.WhereObject(_table, "", dywhere));
 | 
								this.Where(_commonUtils.WhereObject(_table, "", dywhere));
 | 
				
			||||||
			if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure<T1>();
 | 
								if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure<T1>();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -54,6 +54,10 @@ namespace FreeSql.Internal.CommonProvider {
 | 
				
			|||||||
		public IDelete<T1> Where(IEnumerable<T1> items) => this.Where(_commonUtils.WhereItems(_table, "", items));
 | 
							public IDelete<T1> Where(IEnumerable<T1> items) => this.Where(_commonUtils.WhereItems(_table, "", items));
 | 
				
			||||||
		public IDelete<T1> WhereExists<TEntity2>(ISelect<TEntity2> select, bool notExists = false) where TEntity2 : class => this.Where($"{(notExists ? "NOT " : "")}EXISTS({select.ToSql("1")})");
 | 
							public IDelete<T1> WhereExists<TEntity2>(ISelect<TEntity2> select, bool notExists = false) where TEntity2 : class => this.Where($"{(notExists ? "NOT " : "")}EXISTS({select.ToSql("1")})");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public string ToSql() => _whereTimes <= 0 ? null : _where.ToString();
 | 
							public IDelete<T1> AsTable(Func<string, string> tableRule) {
 | 
				
			||||||
 | 
								_tableRule = tableRule;
 | 
				
			||||||
 | 
								return this;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							public string ToSql() => _whereTimes <= 0 ? null : new StringBuilder().Append("DELETE FROM ").Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(_table.DbName) ?? _table.DbName)).Append(" WHERE ").Append(_where).ToString();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,6 +17,7 @@ namespace FreeSql.Internal.CommonProvider {
 | 
				
			|||||||
		protected List<T1> _source = new List<T1>();
 | 
							protected List<T1> _source = new List<T1>();
 | 
				
			||||||
		protected Dictionary<string, bool> _ignore = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
 | 
							protected Dictionary<string, bool> _ignore = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
 | 
				
			||||||
		protected TableInfo _table;
 | 
							protected TableInfo _table;
 | 
				
			||||||
 | 
							protected Func<string, string> _tableRule;
 | 
				
			||||||
		protected DbParameter[] _params;
 | 
							protected DbParameter[] _params;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public InsertProvider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression) {
 | 
							public InsertProvider(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression) {
 | 
				
			||||||
@@ -58,10 +59,14 @@ namespace FreeSql.Internal.CommonProvider {
 | 
				
			|||||||
			return this;
 | 
								return this;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public IInsert<T1> AsTable(Func<string, string> tableRule) {
 | 
				
			||||||
 | 
								_tableRule = tableRule;
 | 
				
			||||||
 | 
								return this;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		public virtual string ToSql() {
 | 
							public virtual string ToSql() {
 | 
				
			||||||
			if (_source == null || _source.Any() == false) return null;
 | 
								if (_source == null || _source.Any() == false) return null;
 | 
				
			||||||
			var sb = new StringBuilder();
 | 
								var sb = new StringBuilder();
 | 
				
			||||||
			sb.Append("INSERT INTO ").Append(_commonUtils.QuoteSqlName(_table.DbName)).Append("(");
 | 
								sb.Append("INSERT INTO ").Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(_table.DbName) ?? _table.DbName)).Append("(");
 | 
				
			||||||
			var colidx = 0;
 | 
								var colidx = 0;
 | 
				
			||||||
			foreach (var col in _table.Columns.Values)
 | 
								foreach (var col in _table.Columns.Values)
 | 
				
			||||||
				if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false) {
 | 
									if (col.Attribute.IsIdentity == false && _ignore.ContainsKey(col.Attribute.Name) == false) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,6 +19,7 @@ namespace FreeSql.Internal.CommonProvider {
 | 
				
			|||||||
		protected StringBuilder _where = new StringBuilder();
 | 
							protected StringBuilder _where = new StringBuilder();
 | 
				
			||||||
		protected List<DbParameter> _params = new List<DbParameter>();
 | 
							protected List<DbParameter> _params = new List<DbParameter>();
 | 
				
			||||||
		internal List<SelectTableInfo> _tables = new List<SelectTableInfo>();
 | 
							internal List<SelectTableInfo> _tables = new List<SelectTableInfo>();
 | 
				
			||||||
 | 
							protected Func<Type, string, string> _tableRule;
 | 
				
			||||||
		protected StringBuilder _join = new StringBuilder();
 | 
							protected StringBuilder _join = new StringBuilder();
 | 
				
			||||||
		protected (int seconds, string key) _cache = (0, null);
 | 
							protected (int seconds, string key) _cache = (0, null);
 | 
				
			||||||
		protected IFreeSql _orm;
 | 
							protected IFreeSql _orm;
 | 
				
			||||||
@@ -31,9 +32,13 @@ namespace FreeSql.Internal.CommonProvider {
 | 
				
			|||||||
			toType.GetField("_limit", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._limit);
 | 
								toType.GetField("_limit", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._limit);
 | 
				
			||||||
			toType.GetField("_skip", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._skip);
 | 
								toType.GetField("_skip", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._skip);
 | 
				
			||||||
			toType.GetField("_select", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._select);
 | 
								toType.GetField("_select", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._select);
 | 
				
			||||||
 | 
								toType.GetField("_orderby", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._orderby);
 | 
				
			||||||
 | 
								toType.GetField("_groupby", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._groupby);
 | 
				
			||||||
 | 
								toType.GetField("_having", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._having);
 | 
				
			||||||
			toType.GetField("_where", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, new StringBuilder().Append(from._where.ToString()));
 | 
								toType.GetField("_where", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, new StringBuilder().Append(from._where.ToString()));
 | 
				
			||||||
			toType.GetField("_params", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, new List<DbParameter>(from._params.ToArray()));
 | 
								toType.GetField("_params", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, new List<DbParameter>(from._params.ToArray()));
 | 
				
			||||||
			toType.GetField("_tables", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, new List<SelectTableInfo>(from._tables.ToArray()));
 | 
								toType.GetField("_tables", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, new List<SelectTableInfo>(from._tables.ToArray()));
 | 
				
			||||||
 | 
								toType.GetField("_tableRule", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._tableRule);
 | 
				
			||||||
			toType.GetField("_join", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, new StringBuilder().Append(from._join.ToString()));
 | 
								toType.GetField("_join", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, new StringBuilder().Append(from._join.ToString()));
 | 
				
			||||||
			toType.GetField("_cache", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._cache);
 | 
								toType.GetField("_cache", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._cache);
 | 
				
			||||||
			//toType.GetField("_orm", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._orm);
 | 
								//toType.GetField("_orm", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(to, from._orm);
 | 
				
			||||||
@@ -397,6 +402,11 @@ namespace FreeSql.Internal.CommonProvider {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
			return (map, field.ToString());
 | 
								return (map, field.ToString());
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public TSelect AsTable(Func<Type, string, string> tableRule) {
 | 
				
			||||||
 | 
								_tableRule = tableRule;
 | 
				
			||||||
 | 
								return this as TSelect;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		public abstract string ToSql(string field = null);
 | 
							public abstract string ToSql(string field = null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public TSelect Where(string sql, object parms = null) => this.WhereIf(true, sql, parms);
 | 
							public TSelect Where(string sql, object parms = null) => this.WhereIf(true, sql, parms);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,6 +17,7 @@ namespace FreeSql.Internal.CommonProvider {
 | 
				
			|||||||
		protected List<T1> _source = new List<T1>();
 | 
							protected List<T1> _source = new List<T1>();
 | 
				
			||||||
		protected Dictionary<string, bool> _ignore = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
 | 
							protected Dictionary<string, bool> _ignore = new Dictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
 | 
				
			||||||
		protected TableInfo _table;
 | 
							protected TableInfo _table;
 | 
				
			||||||
 | 
							protected Func<string, string> _tableRule;
 | 
				
			||||||
		protected StringBuilder _where = new StringBuilder();
 | 
							protected StringBuilder _where = new StringBuilder();
 | 
				
			||||||
		protected StringBuilder _set = new StringBuilder();
 | 
							protected StringBuilder _set = new StringBuilder();
 | 
				
			||||||
		protected List<DbParameter> _params = new List<DbParameter>();
 | 
							protected List<DbParameter> _params = new List<DbParameter>();
 | 
				
			||||||
@@ -105,11 +106,15 @@ namespace FreeSql.Internal.CommonProvider {
 | 
				
			|||||||
		protected abstract void ToSqlCase(StringBuilder caseWhen, ColumnInfo[] primarys);
 | 
							protected abstract void ToSqlCase(StringBuilder caseWhen, ColumnInfo[] primarys);
 | 
				
			||||||
		protected abstract void ToSqlWhen(StringBuilder sb, ColumnInfo[] primarys, object d);
 | 
							protected abstract void ToSqlWhen(StringBuilder sb, ColumnInfo[] primarys, object d);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public IUpdate<T1> AsTable(Func<string, string> tableRule) {
 | 
				
			||||||
 | 
								_tableRule = tableRule;
 | 
				
			||||||
 | 
								return this;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		public string ToSql() {
 | 
							public string ToSql() {
 | 
				
			||||||
			if (_where.Length == 0) return null;
 | 
								if (_where.Length == 0) return null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			var sb = new StringBuilder();
 | 
								var sb = new StringBuilder();
 | 
				
			||||||
			sb.Append("UPDATE ").Append(_commonUtils.QuoteSqlName(_table.DbName)).Append(" SET ");
 | 
								sb.Append("UPDATE ").Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(_table.DbName) ?? _table.DbName)).Append(" SET ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (_set.Length > 0) { //指定 set 更新
 | 
								if (_set.Length > 0) { //指定 set 更新
 | 
				
			||||||
				sb.Append(_set.ToString().Substring(2));
 | 
									sb.Append(_set.ToString().Substring(2));
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,7 +10,7 @@ namespace FreeSql.MySql.Curd {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	class MySqlSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class {
 | 
						class MySqlSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		internal static string ToSqlStatic(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, IFreeSql _orm) {
 | 
							internal static string ToSqlStatic(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, Func<Type, string, string> _tableRule, IFreeSql _orm) {
 | 
				
			||||||
			if (_orm.CodeFirst.IsAutoSyncStructure)
 | 
								if (_orm.CodeFirst.IsAutoSyncStructure)
 | 
				
			||||||
				_orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray());
 | 
									_orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -19,11 +19,12 @@ namespace FreeSql.MySql.Curd {
 | 
				
			|||||||
			var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray();
 | 
								var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray();
 | 
				
			||||||
			var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray();
 | 
								var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray();
 | 
				
			||||||
			for (var a = 0; a < tbsfrom.Length; a++) {
 | 
								for (var a = 0; a < tbsfrom.Length; a++) {
 | 
				
			||||||
				sb.Append(_commonUtils.QuoteSqlName(tbsfrom[a].Table.DbName)).Append(" ").Append(tbsfrom[a].Alias);
 | 
									sb.Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tbsfrom[a].Table.Type, tbsfrom[a].Table.DbName) ?? tbsfrom[a].Table.DbName)).Append(" ").Append(tbsfrom[a].Alias);
 | 
				
			||||||
				if (tbsjoin.Length > 0) {
 | 
									if (tbsjoin.Length > 0) {
 | 
				
			||||||
					//如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1
 | 
										//如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1
 | 
				
			||||||
					for (var b = 1; b < tbsfrom.Length; b++)
 | 
										for (var b = 1; b < tbsfrom.Length; b++) {
 | 
				
			||||||
						sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(tbsfrom[b].Table.DbName)).Append(" ").Append(tbsfrom[b].Alias).Append(" ON 1 = 1");
 | 
											sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tbsfrom[b].Table.Type, tbsfrom[b].Table.DbName) ?? tbsfrom[b].Table.DbName)).Append(" ").Append(tbsfrom[b].Alias).Append(" ON 1 = 1");
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if (a < tbsfrom.Length - 1) sb.Append(", ");
 | 
									if (a < tbsfrom.Length - 1) sb.Append(", ");
 | 
				
			||||||
@@ -41,7 +42,7 @@ namespace FreeSql.MySql.Curd {
 | 
				
			|||||||
						sb.Append(" \r\nRIGHT JOIN ");
 | 
											sb.Append(" \r\nRIGHT JOIN ");
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				sb.Append(_commonUtils.QuoteSqlName(tb.Table.DbName)).Append(" ").Append(tb.Alias).Append(" ON ").Append(tb.On);
 | 
									sb.Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tb.Table.Type, tb.Table.DbName) ?? tb.Table.DbName)).Append(" ").Append(tb.Alias).Append(" ON ").Append(tb.On);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (_join.Length > 0) sb.Append(_join);
 | 
								if (_join.Length > 0) sb.Append(_join);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -78,38 +79,38 @@ namespace FreeSql.MySql.Curd {
 | 
				
			|||||||
		public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8> From<T2, T3, T4, T5, T6, T7, T8>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8>(_orm, _commonUtils, _commonExpression, null); MySqlSelect<T1>.CopyData(this, ret); return ret; }
 | 
							public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8> From<T2, T3, T4, T5, T6, T7, T8>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8>(_orm, _commonUtils, _commonExpression, null); MySqlSelect<T1>.CopyData(this, ret); return ret; }
 | 
				
			||||||
		public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> From<T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>(_orm, _commonUtils, _commonExpression, null); MySqlSelect<T1>.CopyData(this, ret); return ret; }
 | 
							public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> From<T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>(_orm, _commonUtils, _commonExpression, null); MySqlSelect<T1>.CopyData(this, ret); return ret; }
 | 
				
			||||||
		public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> From<T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(_orm, _commonUtils, _commonExpression, null); MySqlSelect<T1>.CopyData(this, ret); return ret; }
 | 
							public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> From<T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(_orm, _commonUtils, _commonExpression, null); MySqlSelect<T1>.CopyData(this, ret); return ret; }
 | 
				
			||||||
		public override string ToSql(string field = null) => ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class MySqlSelect<T1, T2, T3> : FreeSql.Internal.CommonProvider.Select3Provider<T1, T2, T3> where T1 : class where T2 : class where T3 : class {
 | 
						class MySqlSelect<T1, T2, T3> : FreeSql.Internal.CommonProvider.Select3Provider<T1, T2, T3> where T1 : class where T2 : class where T3 : class {
 | 
				
			||||||
		public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => MySqlSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => MySqlSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class MySqlSelect<T1, T2, T3, T4> : FreeSql.Internal.CommonProvider.Select4Provider<T1, T2, T3, T4> where T1 : class where T2 : class where T3 : class where T4 : class {
 | 
						class MySqlSelect<T1, T2, T3, T4> : FreeSql.Internal.CommonProvider.Select4Provider<T1, T2, T3, T4> where T1 : class where T2 : class where T3 : class where T4 : class {
 | 
				
			||||||
		public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => MySqlSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => MySqlSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class MySqlSelect<T1, T2, T3, T4, T5> : FreeSql.Internal.CommonProvider.Select5Provider<T1, T2, T3, T4, T5> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class {
 | 
						class MySqlSelect<T1, T2, T3, T4, T5> : FreeSql.Internal.CommonProvider.Select5Provider<T1, T2, T3, T4, T5> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class {
 | 
				
			||||||
		public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => MySqlSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => MySqlSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class MySqlSelect<T1, T2, T3, T4, T5, T6> : FreeSql.Internal.CommonProvider.Select6Provider<T1, T2, T3, T4, T5, T6> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class {
 | 
						class MySqlSelect<T1, T2, T3, T4, T5, T6> : FreeSql.Internal.CommonProvider.Select6Provider<T1, T2, T3, T4, T5, T6> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class {
 | 
				
			||||||
		public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => MySqlSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => MySqlSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class MySqlSelect<T1, T2, T3, T4, T5, T6, T7> : FreeSql.Internal.CommonProvider.Select7Provider<T1, T2, T3, T4, T5, T6, T7> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class {
 | 
						class MySqlSelect<T1, T2, T3, T4, T5, T6, T7> : FreeSql.Internal.CommonProvider.Select7Provider<T1, T2, T3, T4, T5, T6, T7> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class {
 | 
				
			||||||
		public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => MySqlSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => MySqlSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8> : FreeSql.Internal.CommonProvider.Select8Provider<T1, T2, T3, T4, T5, T6, T7, T8> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class {
 | 
						class MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8> : FreeSql.Internal.CommonProvider.Select8Provider<T1, T2, T3, T4, T5, T6, T7, T8> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class {
 | 
				
			||||||
		public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => MySqlSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => MySqlSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> : FreeSql.Internal.CommonProvider.Select9Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class {
 | 
						class MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> : FreeSql.Internal.CommonProvider.Select9Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class {
 | 
				
			||||||
		public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => MySqlSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => MySqlSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : FreeSql.Internal.CommonProvider.Select10Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class {
 | 
						class MySqlSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : FreeSql.Internal.CommonProvider.Select10Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class {
 | 
				
			||||||
		public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public MySqlSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => MySqlSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => MySqlSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,7 @@ namespace FreeSql.Oracle.Curd {
 | 
				
			|||||||
			_identCol = null;
 | 
								_identCol = null;
 | 
				
			||||||
			var sbtb = new StringBuilder();
 | 
								var sbtb = new StringBuilder();
 | 
				
			||||||
			sbtb.Append("INTO ");
 | 
								sbtb.Append("INTO ");
 | 
				
			||||||
			sbtb.Append(_commonUtils.QuoteSqlName(_table.DbName)).Append("(");
 | 
								sbtb.Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(_table.DbName) ?? _table.DbName)).Append("(");
 | 
				
			||||||
			var colidx = 0;
 | 
								var colidx = 0;
 | 
				
			||||||
			foreach (var col in _table.Columns.Values) {
 | 
								foreach (var col in _table.Columns.Values) {
 | 
				
			||||||
				if (col.Attribute.IsIdentity == true) {
 | 
									if (col.Attribute.IsIdentity == true) {
 | 
				
			||||||
@@ -112,7 +112,7 @@ namespace FreeSql.Oracle.Curd {
 | 
				
			|||||||
//			var colidx = 0;
 | 
					//			var colidx = 0;
 | 
				
			||||||
//			foreach (var col in _table.Columns.Values) {
 | 
					//			foreach (var col in _table.Columns.Values) {
 | 
				
			||||||
//				if (colidx > 0) sb.Append(", ");
 | 
					//				if (colidx > 0) sb.Append(", ");
 | 
				
			||||||
//				sb.Append(_commonUtils.QuoteSqlName(col.CsName)).Append(" ").Append(_commonUtils.QuoteSqlName(_table.DbName)).Append(".").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append("%type");
 | 
					//				sb.Append(_commonUtils.QuoteSqlName(col.CsName)).Append(" ").Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(_table.DbName) ?? _table.DbName))).Append(".").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append("%type");
 | 
				
			||||||
//				++colidx;
 | 
					//				++colidx;
 | 
				
			||||||
//			}
 | 
					//			}
 | 
				
			||||||
//			sb.Append(@");
 | 
					//			sb.Append(@");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,7 +10,7 @@ namespace FreeSql.Oracle.Curd {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	class OracleSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class {
 | 
						class OracleSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		internal static string ToSqlStatic(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, IFreeSql _orm) {
 | 
							internal static string ToSqlStatic(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, Func<Type, string, string> _tableRule, IFreeSql _orm) {
 | 
				
			||||||
			if (_orm.CodeFirst.IsAutoSyncStructure)
 | 
								if (_orm.CodeFirst.IsAutoSyncStructure)
 | 
				
			||||||
				_orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray());
 | 
									_orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -22,11 +22,11 @@ namespace FreeSql.Oracle.Curd {
 | 
				
			|||||||
			var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray();
 | 
								var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray();
 | 
				
			||||||
			var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray();
 | 
								var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray();
 | 
				
			||||||
			for (var a = 0; a < tbsfrom.Length; a++) {
 | 
								for (var a = 0; a < tbsfrom.Length; a++) {
 | 
				
			||||||
				sb.Append(_commonUtils.QuoteSqlName(tbsfrom[a].Table.DbName)).Append(" ").Append(tbsfrom[a].Alias);
 | 
									sb.Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tbsfrom[a].Table.Type, tbsfrom[a].Table.DbName) ?? tbsfrom[a].Table.DbName)).Append(" ").Append(tbsfrom[a].Alias);
 | 
				
			||||||
				if (tbsjoin.Length > 0) {
 | 
									if (tbsjoin.Length > 0) {
 | 
				
			||||||
					//如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1
 | 
										//如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1
 | 
				
			||||||
					for (var b = 1; b < tbsfrom.Length; b++)
 | 
										for (var b = 1; b < tbsfrom.Length; b++)
 | 
				
			||||||
						sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(tbsfrom[b].Table.DbName)).Append(" ").Append(tbsfrom[b].Alias).Append(" ON 1 = 1");
 | 
											sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tbsfrom[b].Table.Type, tbsfrom[b].Table.DbName) ?? tbsfrom[b].Table.DbName)).Append(" ").Append(tbsfrom[b].Alias).Append(" ON 1 = 1");
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if (a < tbsfrom.Length - 1) sb.Append(", ");
 | 
									if (a < tbsfrom.Length - 1) sb.Append(", ");
 | 
				
			||||||
@@ -44,7 +44,7 @@ namespace FreeSql.Oracle.Curd {
 | 
				
			|||||||
						sb.Append(" \r\nRIGHT JOIN ");
 | 
											sb.Append(" \r\nRIGHT JOIN ");
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				sb.Append(_commonUtils.QuoteSqlName(tb.Table.DbName)).Append(" ").Append(tb.Alias).Append(" ON ").Append(tb.On);
 | 
									sb.Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tb.Table.Type, tb.Table.DbName) ?? tb.Table.DbName)).Append(" ").Append(tb.Alias).Append(" ON ").Append(tb.On);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (_join.Length > 0) sb.Append(_join);
 | 
								if (_join.Length > 0) sb.Append(_join);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -89,38 +89,38 @@ namespace FreeSql.Oracle.Curd {
 | 
				
			|||||||
		public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8> From<T2, T3, T4, T5, T6, T7, T8>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8>(_orm, _commonUtils, _commonExpression, null); OracleSelect<T1>.CopyData(this, ret); return ret; }
 | 
							public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8> From<T2, T3, T4, T5, T6, T7, T8>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8>(_orm, _commonUtils, _commonExpression, null); OracleSelect<T1>.CopyData(this, ret); return ret; }
 | 
				
			||||||
		public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> From<T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>(_orm, _commonUtils, _commonExpression, null); OracleSelect<T1>.CopyData(this, ret); return ret; }
 | 
							public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> From<T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>(_orm, _commonUtils, _commonExpression, null); OracleSelect<T1>.CopyData(this, ret); return ret; }
 | 
				
			||||||
		public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> From<T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(_orm, _commonUtils, _commonExpression, null); OracleSelect<T1>.CopyData(this, ret); return ret; }
 | 
							public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> From<T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(_orm, _commonUtils, _commonExpression, null); OracleSelect<T1>.CopyData(this, ret); return ret; }
 | 
				
			||||||
		public override string ToSql(string field = null) => ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class OracleSelect<T1, T2, T3> : FreeSql.Internal.CommonProvider.Select3Provider<T1, T2, T3> where T1 : class where T2 : class where T3 : class {
 | 
						class OracleSelect<T1, T2, T3> : FreeSql.Internal.CommonProvider.Select3Provider<T1, T2, T3> where T1 : class where T2 : class where T3 : class {
 | 
				
			||||||
		public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => OracleSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => OracleSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class OracleSelect<T1, T2, T3, T4> : FreeSql.Internal.CommonProvider.Select4Provider<T1, T2, T3, T4> where T1 : class where T2 : class where T3 : class where T4 : class {
 | 
						class OracleSelect<T1, T2, T3, T4> : FreeSql.Internal.CommonProvider.Select4Provider<T1, T2, T3, T4> where T1 : class where T2 : class where T3 : class where T4 : class {
 | 
				
			||||||
		public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => OracleSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => OracleSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class OracleSelect<T1, T2, T3, T4, T5> : FreeSql.Internal.CommonProvider.Select5Provider<T1, T2, T3, T4, T5> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class {
 | 
						class OracleSelect<T1, T2, T3, T4, T5> : FreeSql.Internal.CommonProvider.Select5Provider<T1, T2, T3, T4, T5> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class {
 | 
				
			||||||
		public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => OracleSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => OracleSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class OracleSelect<T1, T2, T3, T4, T5, T6> : FreeSql.Internal.CommonProvider.Select6Provider<T1, T2, T3, T4, T5, T6> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class {
 | 
						class OracleSelect<T1, T2, T3, T4, T5, T6> : FreeSql.Internal.CommonProvider.Select6Provider<T1, T2, T3, T4, T5, T6> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class {
 | 
				
			||||||
		public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => OracleSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => OracleSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class OracleSelect<T1, T2, T3, T4, T5, T6, T7> : FreeSql.Internal.CommonProvider.Select7Provider<T1, T2, T3, T4, T5, T6, T7> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class {
 | 
						class OracleSelect<T1, T2, T3, T4, T5, T6, T7> : FreeSql.Internal.CommonProvider.Select7Provider<T1, T2, T3, T4, T5, T6, T7> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class {
 | 
				
			||||||
		public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => OracleSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => OracleSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8> : FreeSql.Internal.CommonProvider.Select8Provider<T1, T2, T3, T4, T5, T6, T7, T8> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class {
 | 
						class OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8> : FreeSql.Internal.CommonProvider.Select8Provider<T1, T2, T3, T4, T5, T6, T7, T8> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class {
 | 
				
			||||||
		public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => OracleSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => OracleSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> : FreeSql.Internal.CommonProvider.Select9Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class {
 | 
						class OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> : FreeSql.Internal.CommonProvider.Select9Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class {
 | 
				
			||||||
		public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => OracleSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => OracleSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : FreeSql.Internal.CommonProvider.Select10Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class {
 | 
						class OracleSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : FreeSql.Internal.CommonProvider.Select10Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class {
 | 
				
			||||||
		public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public OracleSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => OracleSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => OracleSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,7 +10,7 @@ namespace FreeSql.PostgreSQL.Curd {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	class PostgreSQLSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class {
 | 
						class PostgreSQLSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		internal static string ToSqlStatic(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, IFreeSql _orm) {
 | 
							internal static string ToSqlStatic(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, Func<Type, string, string> _tableRule, IFreeSql _orm) {
 | 
				
			||||||
			if (_orm.CodeFirst.IsAutoSyncStructure)
 | 
								if (_orm.CodeFirst.IsAutoSyncStructure)
 | 
				
			||||||
				_orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray());
 | 
									_orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -19,11 +19,11 @@ namespace FreeSql.PostgreSQL.Curd {
 | 
				
			|||||||
			var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray();
 | 
								var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray();
 | 
				
			||||||
			var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray();
 | 
								var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray();
 | 
				
			||||||
			for (var a = 0; a < tbsfrom.Length; a++) {
 | 
								for (var a = 0; a < tbsfrom.Length; a++) {
 | 
				
			||||||
				sb.Append(_commonUtils.QuoteSqlName(tbsfrom[a].Table.DbName)).Append(" ").Append(tbsfrom[a].Alias);
 | 
									sb.Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tbsfrom[a].Table.Type, tbsfrom[a].Table.DbName) ?? tbsfrom[a].Table.DbName)).Append(" ").Append(tbsfrom[a].Alias);
 | 
				
			||||||
				if (tbsjoin.Length > 0) {
 | 
									if (tbsjoin.Length > 0) {
 | 
				
			||||||
					//如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1
 | 
										//如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1
 | 
				
			||||||
					for (var b = 1; b < tbsfrom.Length; b++)
 | 
										for (var b = 1; b < tbsfrom.Length; b++)
 | 
				
			||||||
						sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(tbsfrom[b].Table.DbName)).Append(" ").Append(tbsfrom[b].Alias).Append(" ON 1 = 1");
 | 
											sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tbsfrom[b].Table.Type, tbsfrom[b].Table.DbName) ?? tbsfrom[b].Table.DbName)).Append(" ").Append(tbsfrom[b].Alias).Append(" ON 1 = 1");
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if (a < tbsfrom.Length - 1) sb.Append(", ");
 | 
									if (a < tbsfrom.Length - 1) sb.Append(", ");
 | 
				
			||||||
@@ -41,7 +41,7 @@ namespace FreeSql.PostgreSQL.Curd {
 | 
				
			|||||||
						sb.Append(" \r\nRIGHT JOIN ");
 | 
											sb.Append(" \r\nRIGHT JOIN ");
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				sb.Append(_commonUtils.QuoteSqlName(tb.Table.DbName)).Append(" ").Append(tb.Alias).Append(" ON ").Append(tb.On);
 | 
									sb.Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tb.Table.Type, tb.Table.DbName) ?? tb.Table.DbName)).Append(" ").Append(tb.Alias).Append(" ON ").Append(tb.On);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (_join.Length > 0) sb.Append(_join);
 | 
								if (_join.Length > 0) sb.Append(_join);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -80,42 +80,42 @@ namespace FreeSql.PostgreSQL.Curd {
 | 
				
			|||||||
		public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8> From<T2, T3, T4, T5, T6, T7, T8>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new PostgreSQLSelect<T1, T2, T3, T4, T5, T6, T7, T8>(_orm, _commonUtils, _commonExpression, null); PostgreSQLSelect<T1>.CopyData(this, ret); return ret; }
 | 
							public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8> From<T2, T3, T4, T5, T6, T7, T8>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new PostgreSQLSelect<T1, T2, T3, T4, T5, T6, T7, T8>(_orm, _commonUtils, _commonExpression, null); PostgreSQLSelect<T1>.CopyData(this, ret); return ret; }
 | 
				
			||||||
		public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> From<T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new PostgreSQLSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>(_orm, _commonUtils, _commonExpression, null); PostgreSQLSelect<T1>.CopyData(this, ret); return ret; }
 | 
							public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> From<T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new PostgreSQLSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>(_orm, _commonUtils, _commonExpression, null); PostgreSQLSelect<T1>.CopyData(this, ret); return ret; }
 | 
				
			||||||
		public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> From<T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new PostgreSQLSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(_orm, _commonUtils, _commonExpression, null); PostgreSQLSelect<T1>.CopyData(this, ret); return ret; }
 | 
							public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> From<T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new PostgreSQLSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(_orm, _commonUtils, _commonExpression, null); PostgreSQLSelect<T1>.CopyData(this, ret); return ret; }
 | 
				
			||||||
		public override string ToSql(string field = null) => ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	//class PostgreSQLSelect<T1, T2> : FreeSql.Internal.CommonProvider.Select2Provider<T1, T2> where T1 : class where T2 : class {
 | 
						//class PostgreSQLSelect<T1, T2> : FreeSql.Internal.CommonProvider.Select2Provider<T1, T2> where T1 : class where T2 : class {
 | 
				
			||||||
	//	public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
						//	public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
	//	public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllField().field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
						//	public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllField().field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	//}
 | 
						//}
 | 
				
			||||||
	class PostgreSQLSelect<T1, T2, T3> : FreeSql.Internal.CommonProvider.Select3Provider<T1, T2, T3> where T1 : class where T2 : class where T3 : class {
 | 
						class PostgreSQLSelect<T1, T2, T3> : FreeSql.Internal.CommonProvider.Select3Provider<T1, T2, T3> where T1 : class where T2 : class where T3 : class {
 | 
				
			||||||
		public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class PostgreSQLSelect<T1, T2, T3, T4> : FreeSql.Internal.CommonProvider.Select4Provider<T1, T2, T3, T4> where T1 : class where T2 : class where T3 : class where T4 : class {
 | 
						class PostgreSQLSelect<T1, T2, T3, T4> : FreeSql.Internal.CommonProvider.Select4Provider<T1, T2, T3, T4> where T1 : class where T2 : class where T3 : class where T4 : class {
 | 
				
			||||||
		public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class PostgreSQLSelect<T1, T2, T3, T4, T5> : FreeSql.Internal.CommonProvider.Select5Provider<T1, T2, T3, T4, T5> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class {
 | 
						class PostgreSQLSelect<T1, T2, T3, T4, T5> : FreeSql.Internal.CommonProvider.Select5Provider<T1, T2, T3, T4, T5> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class {
 | 
				
			||||||
		public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class PostgreSQLSelect<T1, T2, T3, T4, T5, T6> : FreeSql.Internal.CommonProvider.Select6Provider<T1, T2, T3, T4, T5, T6> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class {
 | 
						class PostgreSQLSelect<T1, T2, T3, T4, T5, T6> : FreeSql.Internal.CommonProvider.Select6Provider<T1, T2, T3, T4, T5, T6> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class {
 | 
				
			||||||
		public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class PostgreSQLSelect<T1, T2, T3, T4, T5, T6, T7> : FreeSql.Internal.CommonProvider.Select7Provider<T1, T2, T3, T4, T5, T6, T7> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class {
 | 
						class PostgreSQLSelect<T1, T2, T3, T4, T5, T6, T7> : FreeSql.Internal.CommonProvider.Select7Provider<T1, T2, T3, T4, T5, T6, T7> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class {
 | 
				
			||||||
		public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class PostgreSQLSelect<T1, T2, T3, T4, T5, T6, T7, T8> : FreeSql.Internal.CommonProvider.Select8Provider<T1, T2, T3, T4, T5, T6, T7, T8> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class {
 | 
						class PostgreSQLSelect<T1, T2, T3, T4, T5, T6, T7, T8> : FreeSql.Internal.CommonProvider.Select8Provider<T1, T2, T3, T4, T5, T6, T7, T8> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class {
 | 
				
			||||||
		public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class PostgreSQLSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> : FreeSql.Internal.CommonProvider.Select9Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class {
 | 
						class PostgreSQLSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> : FreeSql.Internal.CommonProvider.Select9Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class {
 | 
				
			||||||
		public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class PostgreSQLSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : FreeSql.Internal.CommonProvider.Select10Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class {
 | 
						class PostgreSQLSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : FreeSql.Internal.CommonProvider.Select10Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class {
 | 
				
			||||||
		public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public PostgreSQLSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => PostgreSQLSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,13 +10,13 @@ namespace FreeSql.SqlServer.Curd {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	class SqlServerSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class {
 | 
						class SqlServerSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		internal static string ToSqlStatic(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, IFreeSql _orm)
 | 
							internal static string ToSqlStatic(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, Func<Type, string, string> _tableRule, IFreeSql _orm)
 | 
				
			||||||
			=> (_commonUtils as SqlServerUtils).IsSelectRowNumber ?
 | 
								=> (_commonUtils as SqlServerUtils).IsSelectRowNumber ?
 | 
				
			||||||
			ToSqlStaticRowNumber(_commonUtils, _select, field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm) :
 | 
								ToSqlStaticRowNumber(_commonUtils, _select, field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm) :
 | 
				
			||||||
			ToSqlStaticOffsetFetchNext(_commonUtils, _select, field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
								ToSqlStaticOffsetFetchNext(_commonUtils, _select, field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		#region SqlServer 2005 row_number
 | 
							#region SqlServer 2005 row_number
 | 
				
			||||||
		internal static string ToSqlStaticRowNumber(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, IFreeSql _orm) {
 | 
							internal static string ToSqlStaticRowNumber(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, Func<Type, string, string> _tableRule, IFreeSql _orm) {
 | 
				
			||||||
			if (_orm.CodeFirst.IsAutoSyncStructure)
 | 
								if (_orm.CodeFirst.IsAutoSyncStructure)
 | 
				
			||||||
				_orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray());
 | 
									_orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -36,11 +36,11 @@ namespace FreeSql.SqlServer.Curd {
 | 
				
			|||||||
			var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray();
 | 
								var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray();
 | 
				
			||||||
			var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray();
 | 
								var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray();
 | 
				
			||||||
			for (var a = 0; a < tbsfrom.Length; a++) {
 | 
								for (var a = 0; a < tbsfrom.Length; a++) {
 | 
				
			||||||
				sb.Append(_commonUtils.QuoteSqlName(tbsfrom[a].Table.DbName)).Append(" ").Append(tbsfrom[a].Alias);
 | 
									sb.Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tbsfrom[a].Table.Type, tbsfrom[a].Table.DbName) ?? tbsfrom[a].Table.DbName)).Append(" ").Append(tbsfrom[a].Alias);
 | 
				
			||||||
				if (tbsjoin.Length > 0) {
 | 
									if (tbsjoin.Length > 0) {
 | 
				
			||||||
					//如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1
 | 
										//如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1
 | 
				
			||||||
					for (var b = 1; b < tbsfrom.Length; b++)
 | 
										for (var b = 1; b < tbsfrom.Length; b++)
 | 
				
			||||||
						sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(tbsfrom[b].Table.DbName)).Append(" ").Append(tbsfrom[b].Alias).Append(" ON 1 = 1");
 | 
											sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tbsfrom[b].Table.Type, tbsfrom[b].Table.DbName) ?? tbsfrom[b].Table.DbName)).Append(" ").Append(tbsfrom[b].Alias).Append(" ON 1 = 1");
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if (a < tbsfrom.Length - 1) sb.Append(", ");
 | 
									if (a < tbsfrom.Length - 1) sb.Append(", ");
 | 
				
			||||||
@@ -58,7 +58,7 @@ namespace FreeSql.SqlServer.Curd {
 | 
				
			|||||||
						sb.Append(" \r\nRIGHT JOIN ");
 | 
											sb.Append(" \r\nRIGHT JOIN ");
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				sb.Append(_commonUtils.QuoteSqlName(tb.Table.DbName)).Append(" ").Append(tb.Alias).Append(" ON ").Append(tb.On);
 | 
									sb.Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tb.Table.Type, tb.Table.DbName) ?? tb.Table.DbName)).Append(" ").Append(tb.Alias).Append(" ON ").Append(tb.On);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (_join.Length > 0) sb.Append(_join);
 | 
								if (_join.Length > 0) sb.Append(_join);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -89,7 +89,7 @@ namespace FreeSql.SqlServer.Curd {
 | 
				
			|||||||
		#endregion
 | 
							#endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		#region SqlServer 2012+ offset feach next
 | 
							#region SqlServer 2012+ offset feach next
 | 
				
			||||||
		internal static string ToSqlStaticOffsetFetchNext(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, IFreeSql _orm) {
 | 
							internal static string ToSqlStaticOffsetFetchNext(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, Func<Type, string, string> _tableRule, IFreeSql _orm) {
 | 
				
			||||||
			if (_orm.CodeFirst.IsAutoSyncStructure)
 | 
								if (_orm.CodeFirst.IsAutoSyncStructure)
 | 
				
			||||||
				_orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray());
 | 
									_orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -101,11 +101,11 @@ namespace FreeSql.SqlServer.Curd {
 | 
				
			|||||||
			var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray();
 | 
								var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray();
 | 
				
			||||||
			var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray();
 | 
								var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray();
 | 
				
			||||||
			for (var a = 0; a < tbsfrom.Length; a++) {
 | 
								for (var a = 0; a < tbsfrom.Length; a++) {
 | 
				
			||||||
				sb.Append(_commonUtils.QuoteSqlName(tbsfrom[a].Table.DbName)).Append(" ").Append(tbsfrom[a].Alias);
 | 
									sb.Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tbsfrom[a].Table.Type, tbsfrom[a].Table.DbName) ?? tbsfrom[a].Table.DbName)).Append(" ").Append(tbsfrom[a].Alias);
 | 
				
			||||||
				if (tbsjoin.Length > 0) {
 | 
									if (tbsjoin.Length > 0) {
 | 
				
			||||||
					//如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1
 | 
										//如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1
 | 
				
			||||||
					for (var b = 1; b < tbsfrom.Length; b++)
 | 
										for (var b = 1; b < tbsfrom.Length; b++)
 | 
				
			||||||
						sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(tbsfrom[b].Table.DbName)).Append(" ").Append(tbsfrom[b].Alias).Append(" ON 1 = 1");
 | 
											sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tbsfrom[b].Table.Type, tbsfrom[b].Table.DbName) ?? tbsfrom[b].Table.DbName)).Append(" ").Append(tbsfrom[b].Alias).Append(" ON 1 = 1");
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if (a < tbsfrom.Length - 1) sb.Append(", ");
 | 
									if (a < tbsfrom.Length - 1) sb.Append(", ");
 | 
				
			||||||
@@ -123,7 +123,7 @@ namespace FreeSql.SqlServer.Curd {
 | 
				
			|||||||
						sb.Append(" \r\nRIGHT JOIN ");
 | 
											sb.Append(" \r\nRIGHT JOIN ");
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				sb.Append(_commonUtils.QuoteSqlName(tb.Table.DbName)).Append(" ").Append(tb.Alias).Append(" ON ").Append(tb.On);
 | 
									sb.Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tb.Table.Type, tb.Table.DbName) ?? tb.Table.DbName)).Append(" ").Append(tb.Alias).Append(" ON ").Append(tb.On);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (_join.Length > 0) sb.Append(_join);
 | 
								if (_join.Length > 0) sb.Append(_join);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -169,42 +169,42 @@ namespace FreeSql.SqlServer.Curd {
 | 
				
			|||||||
		public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8> From<T2, T3, T4, T5, T6, T7, T8>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new SqlServerSelect<T1, T2, T3, T4, T5, T6, T7, T8>(_orm, _commonUtils, _commonExpression, null); SqlServerSelect<T1>.CopyData(this, ret); return ret; }
 | 
							public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8> From<T2, T3, T4, T5, T6, T7, T8>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new SqlServerSelect<T1, T2, T3, T4, T5, T6, T7, T8>(_orm, _commonUtils, _commonExpression, null); SqlServerSelect<T1>.CopyData(this, ret); return ret; }
 | 
				
			||||||
		public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> From<T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new SqlServerSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>(_orm, _commonUtils, _commonExpression, null); SqlServerSelect<T1>.CopyData(this, ret); return ret; }
 | 
							public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> From<T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new SqlServerSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>(_orm, _commonUtils, _commonExpression, null); SqlServerSelect<T1>.CopyData(this, ret); return ret; }
 | 
				
			||||||
		public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> From<T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new SqlServerSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(_orm, _commonUtils, _commonExpression, null); SqlServerSelect<T1>.CopyData(this, ret); return ret; }
 | 
							public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> From<T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new SqlServerSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(_orm, _commonUtils, _commonExpression, null); SqlServerSelect<T1>.CopyData(this, ret); return ret; }
 | 
				
			||||||
		public override string ToSql(string field = null) => ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	//class SqlServerSelect<T1, T2> : FreeSql.Internal.CommonProvider.Select2Provider<T1, T2> where T1 : class where T2 : class {
 | 
						//class SqlServerSelect<T1, T2> : FreeSql.Internal.CommonProvider.Select2Provider<T1, T2> where T1 : class where T2 : class {
 | 
				
			||||||
	//	public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
						//	public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
	//	public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllField().field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
						//	public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllField().field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	//}
 | 
						//}
 | 
				
			||||||
	class SqlServerSelect<T1, T2, T3> : FreeSql.Internal.CommonProvider.Select3Provider<T1, T2, T3> where T1 : class where T2 : class where T3 : class {
 | 
						class SqlServerSelect<T1, T2, T3> : FreeSql.Internal.CommonProvider.Select3Provider<T1, T2, T3> where T1 : class where T2 : class where T3 : class {
 | 
				
			||||||
		public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class SqlServerSelect<T1, T2, T3, T4> : FreeSql.Internal.CommonProvider.Select4Provider<T1, T2, T3, T4> where T1 : class where T2 : class where T3 : class where T4 : class {
 | 
						class SqlServerSelect<T1, T2, T3, T4> : FreeSql.Internal.CommonProvider.Select4Provider<T1, T2, T3, T4> where T1 : class where T2 : class where T3 : class where T4 : class {
 | 
				
			||||||
		public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class SqlServerSelect<T1, T2, T3, T4, T5> : FreeSql.Internal.CommonProvider.Select5Provider<T1, T2, T3, T4, T5> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class {
 | 
						class SqlServerSelect<T1, T2, T3, T4, T5> : FreeSql.Internal.CommonProvider.Select5Provider<T1, T2, T3, T4, T5> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class {
 | 
				
			||||||
		public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class SqlServerSelect<T1, T2, T3, T4, T5, T6> : FreeSql.Internal.CommonProvider.Select6Provider<T1, T2, T3, T4, T5, T6> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class {
 | 
						class SqlServerSelect<T1, T2, T3, T4, T5, T6> : FreeSql.Internal.CommonProvider.Select6Provider<T1, T2, T3, T4, T5, T6> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class {
 | 
				
			||||||
		public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class SqlServerSelect<T1, T2, T3, T4, T5, T6, T7> : FreeSql.Internal.CommonProvider.Select7Provider<T1, T2, T3, T4, T5, T6, T7> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class {
 | 
						class SqlServerSelect<T1, T2, T3, T4, T5, T6, T7> : FreeSql.Internal.CommonProvider.Select7Provider<T1, T2, T3, T4, T5, T6, T7> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class {
 | 
				
			||||||
		public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class SqlServerSelect<T1, T2, T3, T4, T5, T6, T7, T8> : FreeSql.Internal.CommonProvider.Select8Provider<T1, T2, T3, T4, T5, T6, T7, T8> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class {
 | 
						class SqlServerSelect<T1, T2, T3, T4, T5, T6, T7, T8> : FreeSql.Internal.CommonProvider.Select8Provider<T1, T2, T3, T4, T5, T6, T7, T8> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class {
 | 
				
			||||||
		public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class SqlServerSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> : FreeSql.Internal.CommonProvider.Select9Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class {
 | 
						class SqlServerSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> : FreeSql.Internal.CommonProvider.Select9Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class {
 | 
				
			||||||
		public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class SqlServerSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : FreeSql.Internal.CommonProvider.Select10Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class {
 | 
						class SqlServerSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : FreeSql.Internal.CommonProvider.Select10Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class {
 | 
				
			||||||
		public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public SqlServerSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => SqlServerSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,7 +10,7 @@ namespace FreeSql.Sqlite.Curd {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	class SqliteSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class {
 | 
						class SqliteSelect<T1> : FreeSql.Internal.CommonProvider.Select1Provider<T1> where T1 : class {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		internal static string ToSqlStatic(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, IFreeSql _orm) {
 | 
							internal static string ToSqlStatic(CommonUtils _commonUtils, string _select, string field, StringBuilder _join, StringBuilder _where, string _groupby, string _having, string _orderby, int _skip, int _limit, List<SelectTableInfo> _tables, Func<Type, string, string> _tableRule, IFreeSql _orm) {
 | 
				
			||||||
			if (_orm.CodeFirst.IsAutoSyncStructure)
 | 
								if (_orm.CodeFirst.IsAutoSyncStructure)
 | 
				
			||||||
				_orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray());
 | 
									_orm.CodeFirst.SyncStructure(_tables.Select(a => a.Table.Type).ToArray());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -19,11 +19,11 @@ namespace FreeSql.Sqlite.Curd {
 | 
				
			|||||||
			var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray();
 | 
								var tbsjoin = _tables.Where(a => a.Type != SelectTableInfoType.From).ToArray();
 | 
				
			||||||
			var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray();
 | 
								var tbsfrom = _tables.Where(a => a.Type == SelectTableInfoType.From).ToArray();
 | 
				
			||||||
			for (var a = 0; a < tbsfrom.Length; a++) {
 | 
								for (var a = 0; a < tbsfrom.Length; a++) {
 | 
				
			||||||
				sb.Append(_commonUtils.QuoteSqlName(tbsfrom[a].Table.DbName)).Append(" ").Append(tbsfrom[a].Alias);
 | 
									sb.Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tbsfrom[a].Table.Type, tbsfrom[a].Table.DbName) ?? tbsfrom[a].Table.DbName)).Append(" ").Append(tbsfrom[a].Alias);
 | 
				
			||||||
				if (tbsjoin.Length > 0) {
 | 
									if (tbsjoin.Length > 0) {
 | 
				
			||||||
					//如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1
 | 
										//如果存在 join 查询,则处理 from t1, t2 改为 from t1 inner join t2 on 1 = 1
 | 
				
			||||||
					for (var b = 1; b < tbsfrom.Length; b++)
 | 
										for (var b = 1; b < tbsfrom.Length; b++)
 | 
				
			||||||
						sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(tbsfrom[b].Table.DbName)).Append(" ").Append(tbsfrom[b].Alias).Append(" ON 1 = 1");
 | 
											sb.Append(" \r\nLEFT JOIN ").Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tbsfrom[b].Table.Type, tbsfrom[b].Table.DbName) ?? tbsfrom[b].Table.DbName)).Append(" ").Append(tbsfrom[b].Alias).Append(" ON 1 = 1");
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if (a < tbsfrom.Length - 1) sb.Append(", ");
 | 
									if (a < tbsfrom.Length - 1) sb.Append(", ");
 | 
				
			||||||
@@ -41,7 +41,7 @@ namespace FreeSql.Sqlite.Curd {
 | 
				
			|||||||
						sb.Append(" \r\nRIGHT JOIN ");
 | 
											sb.Append(" \r\nRIGHT JOIN ");
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				sb.Append(_commonUtils.QuoteSqlName(tb.Table.DbName)).Append(" ").Append(tb.Alias).Append(" ON ").Append(tb.On);
 | 
									sb.Append(_commonUtils.QuoteSqlName(_tableRule?.Invoke(tb.Table.Type, tb.Table.DbName) ?? tb.Table.DbName)).Append(" ").Append(tb.Alias).Append(" ON ").Append(tb.On);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (_join.Length > 0) sb.Append(_join);
 | 
								if (_join.Length > 0) sb.Append(_join);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -78,38 +78,38 @@ namespace FreeSql.Sqlite.Curd {
 | 
				
			|||||||
		public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8> From<T2, T3, T4, T5, T6, T7, T8>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new SqliteSelect<T1, T2, T3, T4, T5, T6, T7, T8>(_orm, _commonUtils, _commonExpression, null); SqliteSelect<T1>.CopyData(this, ret); return ret; }
 | 
							public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8> From<T2, T3, T4, T5, T6, T7, T8>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new SqliteSelect<T1, T2, T3, T4, T5, T6, T7, T8>(_orm, _commonUtils, _commonExpression, null); SqliteSelect<T1>.CopyData(this, ret); return ret; }
 | 
				
			||||||
		public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> From<T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new SqliteSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>(_orm, _commonUtils, _commonExpression, null); SqliteSelect<T1>.CopyData(this, ret); return ret; }
 | 
							public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> From<T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new SqliteSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9>(_orm, _commonUtils, _commonExpression, null); SqliteSelect<T1>.CopyData(this, ret); return ret; }
 | 
				
			||||||
		public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> From<T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new SqliteSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(_orm, _commonUtils, _commonExpression, null); SqliteSelect<T1>.CopyData(this, ret); return ret; }
 | 
							public override ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> From<T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, ISelectFromExpression<T1>>> exp) { this.InternalFrom(exp?.Body); var ret = new SqliteSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(_orm, _commonUtils, _commonExpression, null); SqliteSelect<T1>.CopyData(this, ret); return ret; }
 | 
				
			||||||
		public override string ToSql(string field = null) => ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class SqliteSelect<T1, T2, T3> : FreeSql.Internal.CommonProvider.Select3Provider<T1, T2, T3> where T1 : class where T2 : class where T3 : class {
 | 
						class SqliteSelect<T1, T2, T3> : FreeSql.Internal.CommonProvider.Select3Provider<T1, T2, T3> where T1 : class where T2 : class where T3 : class {
 | 
				
			||||||
		public SqliteSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public SqliteSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => SqliteSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => SqliteSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class SqliteSelect<T1, T2, T3, T4> : FreeSql.Internal.CommonProvider.Select4Provider<T1, T2, T3, T4> where T1 : class where T2 : class where T3 : class where T4 : class {
 | 
						class SqliteSelect<T1, T2, T3, T4> : FreeSql.Internal.CommonProvider.Select4Provider<T1, T2, T3, T4> where T1 : class where T2 : class where T3 : class where T4 : class {
 | 
				
			||||||
		public SqliteSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public SqliteSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => SqliteSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => SqliteSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class SqliteSelect<T1, T2, T3, T4, T5> : FreeSql.Internal.CommonProvider.Select5Provider<T1, T2, T3, T4, T5> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class {
 | 
						class SqliteSelect<T1, T2, T3, T4, T5> : FreeSql.Internal.CommonProvider.Select5Provider<T1, T2, T3, T4, T5> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class {
 | 
				
			||||||
		public SqliteSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public SqliteSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => SqliteSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => SqliteSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class SqliteSelect<T1, T2, T3, T4, T5, T6> : FreeSql.Internal.CommonProvider.Select6Provider<T1, T2, T3, T4, T5, T6> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class {
 | 
						class SqliteSelect<T1, T2, T3, T4, T5, T6> : FreeSql.Internal.CommonProvider.Select6Provider<T1, T2, T3, T4, T5, T6> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class {
 | 
				
			||||||
		public SqliteSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public SqliteSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => SqliteSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => SqliteSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class SqliteSelect<T1, T2, T3, T4, T5, T6, T7> : FreeSql.Internal.CommonProvider.Select7Provider<T1, T2, T3, T4, T5, T6, T7> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class {
 | 
						class SqliteSelect<T1, T2, T3, T4, T5, T6, T7> : FreeSql.Internal.CommonProvider.Select7Provider<T1, T2, T3, T4, T5, T6, T7> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class {
 | 
				
			||||||
		public SqliteSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public SqliteSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => SqliteSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => SqliteSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class SqliteSelect<T1, T2, T3, T4, T5, T6, T7, T8> : FreeSql.Internal.CommonProvider.Select8Provider<T1, T2, T3, T4, T5, T6, T7, T8> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class {
 | 
						class SqliteSelect<T1, T2, T3, T4, T5, T6, T7, T8> : FreeSql.Internal.CommonProvider.Select8Provider<T1, T2, T3, T4, T5, T6, T7, T8> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class {
 | 
				
			||||||
		public SqliteSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public SqliteSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => SqliteSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => SqliteSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class SqliteSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> : FreeSql.Internal.CommonProvider.Select9Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class {
 | 
						class SqliteSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> : FreeSql.Internal.CommonProvider.Select9Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class {
 | 
				
			||||||
		public SqliteSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public SqliteSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => SqliteSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => SqliteSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	class SqliteSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : FreeSql.Internal.CommonProvider.Select10Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class {
 | 
						class SqliteSelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> : FreeSql.Internal.CommonProvider.Select10Provider<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> where T1 : class where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class {
 | 
				
			||||||
		public SqliteSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
							public SqliteSelect(IFreeSql orm, CommonUtils commonUtils, CommonExpression commonExpression, object dywhere) : base(orm, commonUtils, commonExpression, dywhere) { }
 | 
				
			||||||
		public override string ToSql(string field = null) => SqliteSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _orm);
 | 
							public override string ToSql(string field = null) => SqliteSelect<T1>.ToSqlStatic(_commonUtils, _select, field ?? this.GetAllFieldExpressionTree().Field, _join, _where, _groupby, _having, _orderby, _skip, _limit, _tables, _tableRule, _orm);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user