mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-22 20:13:41 +08:00
Code First
This commit is contained in:
@@ -10,7 +10,7 @@ namespace OrmTest.Demo
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
[SugarColumn(Length = 40)]
|
||||
[SugarColumn(Length = 100)]
|
||||
public string Name { get; set; }
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public bool IsOk { get; set; }
|
||||
|
@@ -122,6 +122,7 @@ namespace SqlSugar
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Core
|
||||
public Dictionary<string, string> ToClassStringList(string nameSpace = "Models")
|
||||
{
|
||||
this.Namespace = nameSpace;
|
||||
@@ -150,7 +151,7 @@ namespace SqlSugar
|
||||
classText = classText.Replace(DbFirstTemplate.KeyNamespace, this.Namespace);
|
||||
classText = classText.Replace(DbFirstTemplate.KeyUsing, IsAttribute ? (this.UsingTemplate + "using " + PubConst.AssemblyName + ";\r\n") : this.UsingTemplate);
|
||||
classText = classText.Replace(DbFirstTemplate.KeyClassDescription, this.ClassDescriptionTemplate.Replace(DbFirstTemplate.KeyClassDescription, tableInfo.Description + "\r\n"));
|
||||
classText = classText.Replace(DbFirstTemplate.KeySugarTable, IsAttribute ? string.Format(DbFirstTemplate.ValueSugarTable, tableInfo.Name): null);
|
||||
classText = classText.Replace(DbFirstTemplate.KeySugarTable, IsAttribute ? string.Format(DbFirstTemplate.ValueSugarTable, tableInfo.Name) : null);
|
||||
if (columns.IsValuable())
|
||||
{
|
||||
foreach (var item in columns)
|
||||
@@ -183,7 +184,21 @@ namespace SqlSugar
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public void CreateClassFile(string directoryPath, string nameSpace = "Models")
|
||||
{
|
||||
Check.ArgumentNullException(directoryPath, "directoryPath can't null");
|
||||
var classStringList = ToClassStringList(nameSpace);
|
||||
if (classStringList.IsValuable())
|
||||
{
|
||||
foreach (var item in classStringList)
|
||||
{
|
||||
FileHelper.CreateFile(directoryPath.TrimEnd('\\').TrimEnd('/') + string.Format("\\{0}.cs", item.Key), item.Value, Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
private string GetProertypeDefaultValue(DbColumnInfo item)
|
||||
{
|
||||
var result = item.DefaultValue;
|
||||
@@ -203,21 +218,6 @@ namespace SqlSugar
|
||||
result = result.Replace("\r", "\t").Replace("\n", "\t");
|
||||
return result;
|
||||
}
|
||||
|
||||
public void CreateClassFile(string directoryPath, string nameSpace = "Models")
|
||||
{
|
||||
Check.ArgumentNullException(directoryPath, "directoryPath can't null");
|
||||
var classStringList = ToClassStringList(nameSpace);
|
||||
if (classStringList.IsValuable())
|
||||
{
|
||||
foreach (var item in classStringList)
|
||||
{
|
||||
FileHelper.CreateFile(directoryPath.TrimEnd('\\').TrimEnd('/') + string.Format("\\{0}.cs", item.Key), item.Value, Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Private methods
|
||||
private string GetPropertyText(DbColumnInfo item, string PropertyText)
|
||||
{
|
||||
string SugarColumnText = DbFirstTemplate.ValueSugarCoulmn;
|
||||
@@ -266,7 +266,6 @@ namespace SqlSugar
|
||||
return item.DbColumnName;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetPropertyTypeName(DbColumnInfo item)
|
||||
{
|
||||
string result = this.Context.Ado.DbBind.GetPropertyTypeName(item.DataType);
|
||||
@@ -283,7 +282,6 @@ namespace SqlSugar
|
||||
string result = this.Context.Ado.DbBind.GetConvertString(item.DataType) + "(\"" + convertString + "\")";
|
||||
return result;
|
||||
}
|
||||
|
||||
private string GetPropertyDescriptionText(DbColumnInfo item, string propertyDescriptionText)
|
||||
{
|
||||
propertyDescriptionText = propertyDescriptionText.Replace(DbFirstTemplate.KeyPropertyDescription, item.ColumnDescription);
|
||||
@@ -291,7 +289,6 @@ namespace SqlSugar
|
||||
propertyDescriptionText = propertyDescriptionText.Replace(DbFirstTemplate.KeyIsNullable, item.IsNullable.ObjToString());
|
||||
return propertyDescriptionText;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@@ -10,13 +10,9 @@ namespace SqlSugar
|
||||
|
||||
#region DML
|
||||
List<DbTableInfo> GetViewInfoList();
|
||||
|
||||
List<DbTableInfo> GetTableInfoList();
|
||||
|
||||
List<DbColumnInfo> GetColumnInfosByTableName(string tableName);
|
||||
|
||||
List<string> GetIsIdentities(string tableName);
|
||||
|
||||
List<string> GetPrimaries(string tableName);
|
||||
#endregion
|
||||
|
||||
@@ -30,11 +26,9 @@ namespace SqlSugar
|
||||
#region DDL
|
||||
bool DropTable(string tableName);
|
||||
bool TruncateTable(string tableName);
|
||||
|
||||
bool CreateTable(string tableName, List<DbColumnInfo> columns);
|
||||
|
||||
bool AddColumnToTable(string tableName, DbColumnInfo column);
|
||||
|
||||
bool AddKey(string tableName,string columnName,bool isPrimaryKey, bool isIdentity);
|
||||
bool BackupDataBase(string databaseName,string fullFileName);
|
||||
bool DropColumn(string tableName,string columnName);
|
||||
#endregion
|
||||
|
@@ -79,14 +79,14 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return "ALERT TABLE {0} ADD {1} {2}{3} {4} {5} {6}";
|
||||
return "ALTER TABLE {0} ADD {1} {2}{3} {4} {5} {6}";
|
||||
}
|
||||
}
|
||||
protected override string AlterColumnToTableSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "ALERT TABLE {0} ALTER COLUMN {1}{2} {3} ";
|
||||
return "ALTER TABLE {0} ALTER COLUMN {1}{2} {3} ";
|
||||
}
|
||||
}
|
||||
protected override string BackupDataBaseSql
|
||||
|
Reference in New Issue
Block a user