Browse Source

Code optimization

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
5a115243ca
  1. 8
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ExpressionContext.cs
  2. 44
      Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs
  3. 44
      Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteExpressionContext.cs

8
Src/Asp.Net/SqlSugar/ExpressionsToSql/ExpressionContext.cs

@ -96,6 +96,8 @@ namespace SqlSugar
return "@";
}
}
public virtual string SqlTranslationLeft { get { return "["; } }
public virtual string SqlTranslationRight { get { return "]"; } }
#endregion
#region public functions
@ -118,7 +120,7 @@ namespace SqlSugar
else
{
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase));
return "[" + (mappingInfo == null ? entityName : mappingInfo.EntityName) + "]";
return SqlTranslationLeft+ (mappingInfo == null ? entityName : mappingInfo.EntityName) + SqlTranslationRight;
}
}
else
@ -164,11 +166,11 @@ namespace SqlSugar
}
public virtual bool IsTranslationText(string name)
{
return name.Contains("[") && name.Contains("]");
return name.Contains(SqlTranslationLeft) && name.Contains(SqlTranslationRight);
}
public virtual string GetTranslationText(string name)
{
return "[" + name + "]";
return SqlTranslationLeft + name + SqlTranslationRight;
}
public virtual void Resolve(Expression expression, ResolveExpressType resolveType)
{

44
Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs

@ -9,48 +9,8 @@ namespace SqlSugar
{
base.DbMehtods = new MySqlMethod();
}
public override string GetTranslationTableName(string entityName, bool isMapping = true)
{
Check.ArgumentNullException(entityName, string.Format(ErrorMessage.ObjNotExist, "Table Name"));
if (IsTranslationText(entityName)) return entityName;
if (isMapping && this.MappingTables.IsValuable())
{
if (entityName.Contains("."))
{
var columnInfo = entityName.Split('.');
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(columnInfo.Last(), StringComparison.CurrentCultureIgnoreCase));
if (mappingInfo != null)
{
columnInfo[columnInfo.Length - 1] = mappingInfo.EntityName;
}
return string.Join(".", columnInfo.Select(it => GetTranslationText(it)));
}
else
{
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase));
return "`" + (mappingInfo == null ? entityName : mappingInfo.EntityName) + "`";
}
}
else
{
if (entityName.Contains("."))
{
return string.Join(".", entityName.Split('.').Select(it => GetTranslationText(it)));
}
else
{
return GetTranslationText(entityName);
}
}
}
public override bool IsTranslationText(string name)
{
return name.Contains("`") && name.Contains("`");
}
public override string GetTranslationText(string name)
{
return "`" + name + "`";
}
public override string SqlTranslationLeft { get { return "`"; } }
public override string SqlTranslationRight { get { return "`"; } }
}
public class MySqlMethod : DefaultDbMethod, IDbMethods
{

44
Src/Asp.Net/SqlSugar/Realization/Sqlite/SqlBuilder/SqliteExpressionContext.cs

@ -9,48 +9,8 @@ namespace SqlSugar
{
base.DbMehtods = new SqliteMethod();
}
public override string GetTranslationTableName(string entityName, bool isMapping = true)
{
Check.ArgumentNullException(entityName, string.Format(ErrorMessage.ObjNotExist, "Table Name"));
if (IsTranslationText(entityName)) return entityName;
if (isMapping && this.MappingTables.IsValuable())
{
if (entityName.Contains("."))
{
var columnInfo = entityName.Split('.');
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(columnInfo.Last(), StringComparison.CurrentCultureIgnoreCase));
if (mappingInfo != null)
{
columnInfo[columnInfo.Length - 1] = mappingInfo.EntityName;
}
return string.Join(".", columnInfo.Select(it => GetTranslationText(it)));
}
else
{
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase));
return "`" + (mappingInfo == null ? entityName : mappingInfo.EntityName) + "`";
}
}
else
{
if (entityName.Contains("."))
{
return string.Join(".", entityName.Split('.').Select(it => GetTranslationText(it)));
}
else
{
return GetTranslationText(entityName);
}
}
}
public override bool IsTranslationText(string name)
{
return name.Contains("`") && name.Contains("`");
}
public override string GetTranslationText(string name)
{
return "`" + name + "`";
}
public override string SqlTranslationLeft { get { return "`"; } }
public override string SqlTranslationRight { get { return "`"; } }
}
public class SqliteMethod : DefaultDbMethod, IDbMethods
{

Loading…
Cancel
Save