Oracle CodeFirst BUG

This commit is contained in:
sunkaixuan 2018-11-29 11:40:34 +08:00
parent 62f34cd145
commit 58928e07be
2 changed files with 35 additions and 23 deletions

View File

@ -8,29 +8,36 @@ namespace OrmTest.Demo
{
public class CodeTable
{
[SugarColumn(IsPrimaryKey =true)]
[SugarColumn(IsPrimaryKey = true)]
public int Id { get; set; }
[SugarColumn(Length = 21,OldColumnName = "Name2",ColumnDescription ="haha")]
public string Name{ get; set; }
[SugarColumn(IsNullable = true,Length =10)]
[SugarColumn(Length = 21, OldColumnName = "Name2", ColumnDescription = "haha")]
public string Name { get; set; }
[SugarColumn(IsNullable = true, Length = 10)]
public string IsOk { get; set; }
public Guid Guid { get; set; }
[SugarColumn(ColumnDataType ="int")]
[SugarColumn(ColumnDataType = "int")]
public decimal Decimal { get; set; }
[SugarColumn(IsNullable = true)]
public DateTime? DateTime { get; set; }
[SugarColumn(IsNullable = true,OldColumnName = "Dob")]
[SugarColumn(IsNullable = true, OldColumnName = "Dob")]
public double? Dob2 { get; set; }
[SugarColumn(Length =110)]
public string A2{ get; set; }
[SugarColumn(Length = 110)]
public string A2 { get; set; }
}
public class CodeTable2 {
public class CodeTable2
{
public int Id { get; set; }
public string Name { get; set; }
[SugarColumn(IsIgnore =true)]
[SugarColumn(IsIgnore = true)]
public string TestId { get; set; }
}
public class GuidTable
{
public Guid Name { get; set; }
[SugarColumn(IsPrimaryKey = true)]
public Guid Id { get; set; }
}
public class CodeFirst : DemoBase
{
public static void Init()
@ -40,14 +47,15 @@ namespace OrmTest.Demo
ConnectionString = Config.ConnectionString,
DbType = DbType.Oracle,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute
InitKeyType = InitKeyType.Attribute
});
//Backup table
//db.CodeFirst.BackupTable().InitTables(typeof(CodeTable),typeof(CodeTable2));
//No backup table
db.CodeFirst.InitTables(typeof(CodeTable),typeof(CodeTable2));
db.CodeFirst.InitTables(typeof(GuidTable), typeof(CodeTable), typeof(CodeTable2));
}
}
}
}

View File

@ -257,19 +257,19 @@ namespace SqlSugar
}
return true;
}
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName,bool isCache=true)
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName, bool isCache = true)
{
string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
cacheKey = GetCacheKey(cacheKey);
if (!isCache)
return GetColumnInfosByTableName(tableName);
else
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
() =>
{
return GetColumnInfosByTableName(tableName);
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
() =>
{
return GetColumnInfosByTableName(tableName);
});
});
}
private List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
@ -282,7 +282,7 @@ namespace SqlSugar
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
List<DbColumnInfo> result = new List<DbColumnInfo>();
var schemaTable = reader.GetSchemaTable();
foreach (DataRow row in schemaTable.Rows)
foreach (System.Data.DataRow row in schemaTable.Rows)
{
DbColumnInfo column = new DbColumnInfo()
{
@ -330,7 +330,7 @@ namespace SqlSugar
string sql = "SELECT COMMENTS FROM USER_TAB_COMMENTS WHERE TABLE_NAME =@tableName ORDER BY TABLE_NAME";
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
this.Context.Ado.IsEnableLogEvent = false;
var pks = this.Context.Ado.SqlQuery<string>(sql,new { tableName=tableName.ToUpper() });
var pks = this.Context.Ado.SqlQuery<string>(sql, new { tableName = tableName.ToUpper() });
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
return pks;
});
@ -350,7 +350,7 @@ namespace SqlSugar
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
return pks;
});
return comments.HasValue() ? comments.First(it=>it.DbColumnName.Equals(filedName,StringComparison.CurrentCultureIgnoreCase)).ColumnDescription : "";
return comments.HasValue() ? comments.First(it => it.DbColumnName.Equals(filedName, StringComparison.CurrentCultureIgnoreCase)).ColumnDescription : "";
}
@ -364,6 +364,10 @@ namespace SqlSugar
{
item.Length = 50;
}
if (item.DataType == "varchar" && item.Length == 0)
{
item.Length = 50;
}
}
}
string sql = GetCreateTableSql(tableName, columns);