Browse Source

-

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
cb4bc9c3ef
  1. 33
      SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs
  2. 2
      SqlSugar/Abstract/DbFirstProvider/DbFirstTemplate.cs
  3. 1
      SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs
  4. 1
      SqlSugar/Interface/ISqlBuilder/ISqlBuilder.cs

33
SqlSugar/Abstract/DbFirstProvider/DbFirstProvider.cs

@ -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;
}

2
SqlSugar/Abstract/DbFirstProvider/DbFirstTemplate.cs

@ -35,7 +35,7 @@ namespace SqlSugar
PropertySpace + "/// Nullable:{IsNullable}\r\n" +
PropertySpace + "/// </summary>";
public static string ConstructorTemplate = PropertySpace + "this.{PropertyName} ={PropertyType}(\"{DefaultValue}\");\r\n";
public static string ConstructorTemplate = PropertySpace + " this.{PropertyName} ={DefaultValue};\r\n";
public static string UsingTemplate = "using System;\r\n" +
"using System.Linq;\r\n" +

1
SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs

@ -45,6 +45,7 @@ namespace SqlSugar
}
public virtual string SqlParameterKeyWord { get { return "@"; } }
public virtual string SqlFalse { get { return "1=2 "; } }
public virtual string SqlDateNow { get { return "GETDATE()"; } }
#endregion
}
}

1
SqlSugar/Interface/ISqlBuilder/ISqlBuilder.cs

@ -20,6 +20,7 @@ namespace SqlSugar
string SqlParameterKeyWord { get; }
string SqlFalse { get; }
string SqlDateNow { get; }
string GetTranslationTableName(string name);
string GetTranslationColumnName(string entityName, string propertyName);

Loading…
Cancel
Save