|
|
@ -2,6 +2,8 @@ |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
|
|
|
|
namespace SqlSugar |
|
|
|
{ |
|
|
|
public abstract partial class DbFirstProvider : IDbFirst |
|
|
@ -16,6 +18,13 @@ namespace SqlSugar |
|
|
|
private string Namespace { get; set; } |
|
|
|
private bool IsAttribute { get; set; } |
|
|
|
private bool IsDefaultValue { get; set; } |
|
|
|
private ISqlBuilder SqlBuilder |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
return InstanceFactory.GetSqlbuilder(this.Context.CurrentConnectionConfig); |
|
|
|
} |
|
|
|
} |
|
|
|
private List<DbTableInfo> TableInfoList { get; set; } |
|
|
|
|
|
|
|
public DbFirstProvider() |
|
|
@ -165,8 +174,7 @@ namespace SqlSugar |
|
|
|
if (ConstructorText.IsValuable() && item.DefaultValue.IsValuable()) |
|
|
|
{ |
|
|
|
ConstructorText = ConstructorText.Replace(DbFirstTemplate.KeyPropertyName, propertyName); |
|
|
|
ConstructorText = ConstructorText.Replace(DbFirstTemplate.KeyPropertyType, propertyTypeName); |
|
|
|
ConstructorText = ConstructorText.Replace(DbFirstTemplate.KeyDefaultValue, GetPropertyTypeConvert(item)) +(isLast?"":"\r\n"+DbFirstTemplate.KeyPropertyName); |
|
|
|
ConstructorText = ConstructorText.Replace(DbFirstTemplate.KeyDefaultValue, GetPropertyTypeConvert(item)) + (isLast ? "" : DbFirstTemplate.ConstructorTemplate); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -180,16 +188,21 @@ namespace SqlSugar |
|
|
|
|
|
|
|
private string GetProertypeDefaultValue(DbColumnInfo item) |
|
|
|
{ |
|
|
|
if (item.DefaultValue == null) return null; |
|
|
|
string result = item.DefaultValue.TrimStart('(').TrimEnd(')').TrimStart('\'').TrimEnd('\''); |
|
|
|
if (item.DefaultValue.GetType() == PubConst.DateType) |
|
|
|
var result = item.DefaultValue; |
|
|
|
if (result == null) return null; |
|
|
|
if (Regex.IsMatch(result, @"^\(\'(.+)\'\)$")) |
|
|
|
{ |
|
|
|
return result.ObjToDate().ToString("yyyy-MM-dd hh:mm:ss.fff"); |
|
|
|
result = Regex.Match(result, @"^\(\'(.+)\'\)$").Groups[1].Value; |
|
|
|
} |
|
|
|
else |
|
|
|
if (Regex.IsMatch(result, @"^\((.+)\)$")) |
|
|
|
{ |
|
|
|
return result; |
|
|
|
result = Regex.Match(result, @"^\((.+)\)$").Groups[1].Value; |
|
|
|
} |
|
|
|
if (result.Equals(this.SqlBuilder.SqlDateNow,StringComparison.CurrentCultureIgnoreCase)) |
|
|
|
{ |
|
|
|
result = "DateTime.Now"; |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
public void CreateClassFile(string directoryPath, string nameSpace = "Models") |
|
|
@ -242,7 +255,9 @@ namespace SqlSugar |
|
|
|
} |
|
|
|
private string GetPropertyTypeConvert(DbColumnInfo item) |
|
|
|
{ |
|
|
|
string result = "(\""+GetProertypeDefaultValue(item) +"\")"; |
|
|
|
var convertString = GetProertypeDefaultValue(item); |
|
|
|
if (convertString == "DateTime.Now"|| convertString==null) return convertString; |
|
|
|
string result = this.Context.Ado.DbBind.GetCSharpConvert(item.DataType) + "(\"" + convertString + "\")"; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|