From 14412a45bd1ba1c6f2b3087dd045c3d839fcae51 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Thu, 17 Aug 2017 23:02:02 +0800 Subject: [PATCH] Code optimization --- .../Realization/MySql/SqlBuilder/MySqlBuilder.cs | 9 +++++---- .../Realization/SqlServer/SqlBuilder/SqlServerBuilder.cs | 9 +++++---- .../Realization/Sqlite/SqlBuilder/SqliteBuilder.cs | 5 ++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlBuilder.cs b/Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlBuilder.cs index 86e22d4d0..fd31a3e65 100644 --- a/Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlBuilder.cs @@ -9,15 +9,16 @@ namespace SqlSugar public override string GetTranslationTableName(string name) { Check.ArgumentNullException(name, string.Format(ErrorMessage.ObjNotExist, "Table Name")); + if (name.IsContainsIn("`", "(", ")")) + { + return name; + } var context = this.Context; var mappingInfo = context .MappingTables .FirstOrDefault(it => it.EntityName.Equals(name, StringComparison.CurrentCultureIgnoreCase)); name = (mappingInfo == null ? name : mappingInfo.DbTableName); - if (name.Contains("`")) - return name; - else - return "`" + name + "`"; + return "`" + name + "`"; } public override string GetTranslationColumnName(string entityName, string propertyName) { diff --git a/Src/Asp.Net/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerBuilder.cs b/Src/Asp.Net/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerBuilder.cs index a4200ad9f..488e70ece 100644 --- a/Src/Asp.Net/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerBuilder.cs @@ -12,15 +12,16 @@ namespace SqlSugar public override string GetTranslationTableName(string name) { Check.ArgumentNullException(name, string.Format(ErrorMessage.ObjNotExist, "Table Name")); + if (name.IsContainsIn("(", ")", "[")) + { + return name; + } var context = this.Context; var mappingInfo = context .MappingTables .FirstOrDefault(it => it.EntityName.Equals(name, StringComparison.CurrentCultureIgnoreCase)); name = (mappingInfo == null ? name : mappingInfo.DbTableName); - if (name.Contains("[")) - return name; - else - return "[" + name + "]"; + return "[" + name + "]"; } public override string GetTranslationColumnName(string entityName, string propertyName) { diff --git a/Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteBuilder.cs b/Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteBuilder.cs index 47d45cadb..97ad6182d 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteBuilder.cs @@ -9,8 +9,11 @@ namespace SqlSugar public override string GetTranslationTableName(string name) { - if (name.Contains("`")) return name; Check.ArgumentNullException(name, string.Format(ErrorMessage.ObjNotExist, "Table Name")); + if (name.IsContainsIn("`", "(", ")")) + { + return name; + } var context = this.Context; var mappingInfo = context .MappingTables