diff --git a/Src/Asp.Net/OracleTest/Demos/5_CodeFirst.cs b/Src/Asp.Net/OracleTest/Demos/5_CodeFirst.cs index 94fa0f606..7bd5f8d30 100644 --- a/Src/Asp.Net/OracleTest/Demos/5_CodeFirst.cs +++ b/Src/Asp.Net/OracleTest/Demos/5_CodeFirst.cs @@ -11,7 +11,7 @@ namespace OrmTest.Demo [SugarColumn(IsNullable =false ,IsPrimaryKey =true,IsIdentity =true)] public int Id { get; set; } - [SugarColumn(Length = 21,OldColumnName = "Name2")] + [SugarColumn(Length = 21,OldColumnName = "Name2",ColumnDescription ="haha")] public string Name{ get; set; } [SugarColumn(IsNullable = true,Length =10)] public string IsOk { get; set; } @@ -24,6 +24,7 @@ namespace OrmTest.Demo public double? Dob2 { get; set; } [SugarColumn(Length =110)] public string A1 { get; set; } + public string X2 { get; set; } } public class CodeTable2 { public int Id { get; set; } diff --git a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs index 9bbbb5886..eee4b2c96 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs @@ -11,7 +11,7 @@ namespace SqlSugar public virtual SqlSugarClient Context { get; set; } private bool IsBackupTable { get; set; } private int MaxBackupDataRows { get; set; } - private int DefultLength { get; set; } + protected virtual int DefultLength { get; set; } #endregion #region Public methods @@ -162,8 +162,8 @@ namespace SqlSugar { var dbColumn = dbColumns.FirstOrDefault(dc => dc.DbColumnName.Equals(item.DbColumnName, StringComparison.CurrentCultureIgnoreCase)); if (dbColumn == null) continue; - var pkDiff = item.IsPrimarykey != dbColumn.IsPrimarykey; - var idEntityDiff = item.IsIdentity != dbColumn.IsIdentity; + bool pkDiff, idEntityDiff; + KeyAction(item, dbColumn, out pkDiff, out idEntityDiff); if (dbColumn != null && pkDiff && !idEntityDiff) { var isAdd = item.IsPrimarykey; @@ -188,6 +188,12 @@ namespace SqlSugar } } + protected virtual void KeyAction(EntityColumnInfo item, DbColumnInfo dbColumn, out bool pkDiff, out bool idEntityDiff) + { + pkDiff = item.IsPrimarykey != dbColumn.IsPrimarykey; + idEntityDiff = item.IsIdentity != dbColumn.IsIdentity; + } + protected virtual void ChangeKey(EntityInfo entityInfo, string tableName, EntityColumnInfo item) { string constraintName = string.Format("PK_{0}_{1}", tableName, item.DbColumnName); diff --git a/Src/Asp.Net/SqlSugar/Realization/Oracle/CodeFirst/OracleCodeFirst.cs b/Src/Asp.Net/SqlSugar/Realization/Oracle/CodeFirst/OracleCodeFirst.cs index 82a43712b..3d7cafbe2 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Oracle/CodeFirst/OracleCodeFirst.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Oracle/CodeFirst/OracleCodeFirst.cs @@ -7,6 +7,12 @@ namespace SqlSugar { public class OracleCodeFirst : CodeFirstProvider { + public OracleCodeFirst() { + if (DefultLength == 0) + DefultLength = 40; + } + protected override int DefultLength { get; set; } + protected override void GetDbType(EntityColumnInfo item, Type propertyType, DbColumnInfo result) { if (!string.IsNullOrEmpty(item.DataType)) @@ -29,5 +35,11 @@ namespace SqlSugar } } } + + protected override void KeyAction(EntityColumnInfo item, DbColumnInfo dbColumn, out bool pkDiff, out bool idEntityDiff) + { + pkDiff = item.IsPrimarykey != dbColumn.IsPrimarykey; + idEntityDiff = false; + } } } diff --git a/Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs b/Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs index 035a66ae1..d239b8d45 100644 --- a/Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs +++ b/Src/Asp.Net/SqlSugar/Realization/Oracle/DbMaintenance/OracleDbMaintenance.cs @@ -55,14 +55,14 @@ namespace SqlSugar { get { - return "ALTER 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 "ALTER TABLE {0} ALTER COLUMN {1} {2}{3} {4} {5} {6}"; + return "ALTER TABLE {0} modify ({1} {2}{3} {4} {5} {6}) "; } } protected override string BackupDataBaseSql @@ -145,14 +145,14 @@ namespace SqlSugar { get { - return "NULL"; + return ""; } } protected override string CreateTableNotNull { get { - return "NOT NULL"; + return ""; } } protected override string CreateTablePirmaryKey @@ -174,7 +174,7 @@ namespace SqlSugar { get { - return "comment on column {1}.{0} is '{2}';"; + return "comment on column {1}.{0} is '{2}'"; } } @@ -182,7 +182,7 @@ namespace SqlSugar { get { - return "comment on column {1}.{0} is '';"; + return "comment on column {1}.{0} is ''"; } } @@ -198,7 +198,7 @@ namespace SqlSugar { get { - return "comment on table {0} is '{1}';"; + return "comment on table {0} is '{1}'"; } } @@ -206,7 +206,7 @@ namespace SqlSugar { get { - return "comment on table {0} is '';"; + return "comment on table {0} is ''"; } } @@ -220,6 +220,43 @@ namespace SqlSugar #endregion #region Methods + public override bool AddRemark(EntityInfo entity) + { + var db = this.Context; + var columns = entity.Columns.Where(it => it.IsIgnore == false).ToList(); + + foreach (var item in columns) + { + if (item.ColumnDescription != null) + { + //column remak + if (db.DbMaintenance.IsAnyColumnRemark(item.DbColumnName.ToUpper(), item.DbTableName.ToUpper())) + { + db.DbMaintenance.DeleteColumnRemark(item.DbColumnName.ToUpper(), item.DbTableName.ToUpper()); + db.DbMaintenance.AddColumnRemark(item.DbColumnName.ToUpper(), item.DbTableName.ToUpper(), item.ColumnDescription); + } + else + { + db.DbMaintenance.AddColumnRemark(item.DbColumnName.ToUpper(), item.DbTableName.ToUpper(), item.ColumnDescription); + } + } + } + + //table remak + if (entity.TableDescription != null) + { + if (db.DbMaintenance.IsAnyTableRemark(entity.DbTableName)) + { + db.DbMaintenance.DeleteTableRemark(entity.DbTableName); + db.DbMaintenance.AddTableRemark(entity.DbTableName, entity.TableDescription); + } + else + { + db.DbMaintenance.AddTableRemark(entity.DbTableName, entity.TableDescription); + } + } + return true; + } public override List GetColumnInfosByTableName(string tableName,bool isCache=true) { string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();