Browse Source

Synchronization code

pull/29/head
sunkaixuan 2 years ago
parent
commit
531735a187
  1. 4
      Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs
  2. 1
      Src/Asp.Net/SqlSugar/Entities/ConnMoreSettings.cs
  3. 19
      Src/Asp.Net/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs
  4. 12
      Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs

4
Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs

@ -573,6 +573,10 @@ namespace SqlSugar
{
return false;
}
if (properyTypeName?.ToLower() == "varchar" && dataType?.ToLower() == "nvarchar")
{
return false;
}
if (properyTypeName?.ToLower() == "number" && dataType?.ToLower() == "decimal")
{
return false;

1
Src/Asp.Net/SqlSugar/Entities/ConnMoreSettings.cs

@ -18,5 +18,6 @@ namespace SqlSugar
public bool? TableEnumIsString { get; set; }
public DateTime? DbMinDate { get; set; } = Convert.ToDateTime("1900-01-01");
public bool IsNoReadXmlDescription { get; set; }
public bool SqlServerCodeFirstNvarchar { get; set; }
}
}

19
Src/Asp.Net/SqlSugar/Realization/SqlServer/DbMaintenance/SqlServerDbMaintenance.cs

@ -321,6 +321,17 @@ namespace SqlSugar
#endregion
#region Methods
public override bool UpdateColumn(string tableName, DbColumnInfo column)
{
if (column.DataType != null && this.Context.CurrentConnectionConfig?.MoreSettings?.SqlServerCodeFirstNvarchar == true)
{
if (!column.DataType.ToLower().Contains("nvarchar"))
{
column.DataType = column.DataType.ToLower().Replace("varchar", "nvarchar");
}
}
return base.UpdateColumn(tableName, column);
}
public override bool IsAnyTable(string tableName, bool isCache = true)
{
if (tableName.Contains("."))
@ -536,6 +547,14 @@ namespace SqlSugar
item.DecimalDigits = 4;
item.Length = 18;
}
else if (item.DataType != null && this.Context.CurrentConnectionConfig?.MoreSettings?.SqlServerCodeFirstNvarchar == true)
{
if (!item.DataType.ToLower().Contains("nvarchar"))
{
item.DataType = item.DataType.ToLower().Replace("varchar", "nvarchar");
}
}
}
string sql = GetCreateTableSql(tableName, columns);
this.Context.Ado.ExecuteCommand(sql);

12
Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs

@ -17,13 +17,6 @@ namespace SqlSugar
{
public class UtilMethods
{
public static string ToUnderLineNew(string str)
{
if(!str.Contains("_"))
return string.Concat(str.Select((x, i) => i > 0 && char.IsUpper(x) ? "_" + x.ToString() : x.ToString()));
else
return str;
}
public static string ToUnderLine(string str, bool isToUpper = false)
{
if (isToUpper)
@ -181,8 +174,9 @@ namespace SqlSugar
TableEnumIsString = it.MoreSettings.TableEnumIsString,
DisableMillisecond = it.MoreSettings.DisableMillisecond,
DbMinDate=it.MoreSettings.DbMinDate,
IsNoReadXmlDescription=it.MoreSettings.IsNoReadXmlDescription
IsNoReadXmlDescription=it.MoreSettings.IsNoReadXmlDescription,
SqlServerCodeFirstNvarchar=it.MoreSettings.SqlServerCodeFirstNvarchar
},
SqlMiddle = it.SqlMiddle == null ? null : new SqlMiddle
{

Loading…
Cancel
Save