Synchronization code

This commit is contained in:
sunkaixuan 2022-10-28 16:32:19 +08:00
parent 2943298fb6
commit babcdecc83
3 changed files with 22 additions and 3 deletions

View File

@ -13,6 +13,7 @@ namespace SqlSugar
public bool DisableNvarchar { get; set; }
public bool DisableMillisecond { get; set; }
public bool PgSqlIsAutoToLower = true;
public bool PgSqlIsAutoToLowerCodeFirst = true;
public int DefaultCacheDurationInSeconds { get; set; }
public bool? TableEnumIsString { get; set; }
public DateTime? DbMinDate { get; set; } = Convert.ToDateTime("1900-01-01");

View File

@ -358,7 +358,7 @@ namespace SqlSugar
string primaryKeyInfo = null;
if (columns.Any(it => it.IsPrimarykey) && isCreatePrimaryKey)
{
primaryKeyInfo = string.Format(", Primary key({0})", string.Join(",", columns.Where(it => it.IsPrimarykey).Select(it => this.SqlBuilder.GetTranslationColumnName(it.DbColumnName.ToLower()))));
primaryKeyInfo = string.Format(", Primary key({0})", string.Join(",", columns.Where(it => it.IsPrimarykey).Select(it => this.SqlBuilder.GetTranslationColumnName(it.DbColumnName.ToLower(isAutoToLowerCodeFirst)))));
}
sql = sql.Replace("$PrimaryKey", primaryKeyInfo);
@ -389,7 +389,7 @@ namespace SqlSugar
}
string nullType = item.IsNullable ? this.CreateTableNull : CreateTableNotNull;
string primaryKey = null;
string addItem = string.Format(this.CreateTableColumn, this.SqlBuilder.GetTranslationColumnName(columnName.ToLower()), dataType, dataSize, nullType, primaryKey, "");
string addItem = string.Format(this.CreateTableColumn, this.SqlBuilder.GetTranslationColumnName(columnName.ToLower(isAutoToLowerCodeFirst)), dataType, dataSize, nullType, primaryKey, "");
if (item.IsIdentity)
{
string length = dataType.Substring(dataType.Length - 1);
@ -398,7 +398,7 @@ namespace SqlSugar
}
columnArray.Add(addItem);
}
string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName(tableName.ToLower()), string.Join(",\r\n", columnArray));
string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName(tableName.ToLower(isAutoToLowerCodeFirst)), string.Join(",\r\n", columnArray));
return tableString;
}
public override bool IsAnyConstraint(string constraintName)
@ -459,6 +459,23 @@ namespace SqlSugar
#endregion
#region Helper
private bool isAutoToLowerCodeFirst
{
get
{
if (this.Context.CurrentConnectionConfig.MoreSettings == null) return true;
else if (
this.Context.CurrentConnectionConfig.MoreSettings.PgSqlIsAutoToLower == false &&
this.Context.CurrentConnectionConfig.MoreSettings?.PgSqlIsAutoToLowerCodeFirst == false)
{
return false;
}
else
{
return true;
}
}
}
private string GetSchema()
{
var schema = "public";

View File

@ -151,6 +151,7 @@ namespace SqlSugar
DefaultCacheDurationInSeconds = it.MoreSettings.DefaultCacheDurationInSeconds,
DisableNvarchar = it.MoreSettings.DisableNvarchar,
PgSqlIsAutoToLower = it.MoreSettings.PgSqlIsAutoToLower,
PgSqlIsAutoToLowerCodeFirst= it.MoreSettings.PgSqlIsAutoToLowerCodeFirst,
IsAutoRemoveDataCache = it.MoreSettings.IsAutoRemoveDataCache,
IsWithNoLockQuery = it.MoreSettings.IsWithNoLockQuery,
TableEnumIsString = it.MoreSettings.TableEnumIsString,