/// <summary> /// 属性转换为列 /// </summary> /// <param name="p"></param> /// <returns></returns> public string Property2Column(PropertyBuildModel p) { switch (p.Type) { case PropertyType.Bool: return("[BIT]"); case PropertyType.Byte: return("[TINYINT]"); case PropertyType.DateTime: return("[DATETIME]"); case PropertyType.Decimal: return($"[DECIMAL]({p.Precision},{p.Scale})"); case PropertyType.Double: return($"[FLOAT]({p.Precision})"); case PropertyType.Enum: return("[SMALLINT]"); case PropertyType.Guid: return("[UNIQUEIDENTIFIER]"); case PropertyType.Int: return("[INT]"); case PropertyType.Long: return("[BIGINT]"); case PropertyType.Short: return("[SMALLINT]"); default: return($"[NVARCHAR]({(p.Length > 0 ? p.Length.ToString() : "MAX")})"); } }
/// <summary> /// 属性转换为列 /// </summary> /// <param name="p"></param> /// <returns></returns> public string Property2Column(PropertyBuildModel p) { switch (p.Type) { case PropertyType.Bool: return("integer"); case PropertyType.Byte: return("integer"); case PropertyType.Decimal: return($"DECIMAL({p.Precision},{p.Scale})"); case PropertyType.Double: return($"integer"); case PropertyType.Enum: return("integer"); case PropertyType.Guid: return("UNIQUEIDENTIFIER"); case PropertyType.Int: return("integer"); case PropertyType.Long: return("integer"); case PropertyType.Short: return("integer"); default: return("text"); } }
/// <summary> /// 属性转换为列 /// </summary> /// <param name="p"></param> /// <returns></returns> public string Property2Column(PropertyBuildModel p) { switch (p.Type) { case PropertyType.Bool: return("TINYINT(1)"); case PropertyType.Byte: return("TINYINT(3)"); case PropertyType.DateTime: return("DATETIME"); case PropertyType.Decimal: return($"DECIMAL({p.Precision},{p.Scale})"); case PropertyType.Double: return($"DOUBLE"); case PropertyType.Enum: return("TINYINT(3)"); case PropertyType.Guid: return("CHAR(36)"); case PropertyType.Int: return("INT"); case PropertyType.Long: return("BIGINT"); case PropertyType.Short: return("SMALLINT"); default: return(p.Length > 0 ? $"VARCHAR({p.Length})" : "TEXT"); } }
/// <summary> /// 获取默认值 /// </summary> /// <returns></returns> public string GetDefaultValue(PropertyBuildModel property) { if (!property.HasDefaultValue) { return(string.Empty); } if (property.Type == PropertyType.DateTime) { return(" = DateTime.Now;"); } if (property.Type == PropertyType.String) { return(" = string.Empty;"); } return(string.Empty); }