Browse Source

Update oracle codefirst

pull/10/head
sunkaixuna 3 years ago
parent
commit
3a3fbdba2f
  1. 19
      Src/Asp.Net/OracleTest/UnitTest/UCodeFirst.cs
  2. 20
      Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs

19
Src/Asp.Net/OracleTest/UnitTest/UCodeFirst.cs

@ -1,4 +1,5 @@
using System;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -14,6 +15,22 @@ namespace OrmTest
Db.DbMaintenance.DropTable("UnitCodeTest1");
Demo2();
Demo3();
Db.CodeFirst.InitTables<TESTA1>();
var xx = Db.DbMaintenance.GetColumnInfosByTableName("TESTA1", false);
Db.DbMaintenance.AddColumn("TESTA1", new DbColumnInfo()
{
DbColumnName = "aaa" + new Random().Next(2, 99999),
PropertyName = "aaa" + new Random().Next(2, 99999),
TableName = "TESTA1",
IsNullable = true,
DataType = "varchar",
Length = 11
});
// db.Utilities.RemoveCacheAll();
var xxxxx = Db.DbMaintenance.GetColumnInfosByTableName("TESTA1", false);
}
public class TESTA1 {
public string X { get; set; }
}
private static void Demo2()

20
Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs

@ -191,7 +191,7 @@ namespace SqlSugar
dbColumns.Any(dc => dc.DbColumnName.Equals(ec.DbColumnName)
&& ((ec.Length != dc.Length && !UtilMethods.GetUnderType(ec.PropertyInfo).IsEnum() && UtilMethods.GetUnderType(ec.PropertyInfo).IsIn(UtilConstants.StringType)) ||
ec.IsNullable != dc.IsNullable ||
IsSamgeType(ec, dc)))).ToList();
IsNoSamgeType(ec, dc)))).ToList();
var renameColumns = entityColumns
.Where(it => !string.IsNullOrEmpty(it.OldDbColumnName))
.Where(entityColumn => dbColumns.Any(dbColumn => entityColumn.OldDbColumnName.Equals(dbColumn.DbColumnName, StringComparison.CurrentCultureIgnoreCase)))
@ -343,7 +343,7 @@ namespace SqlSugar
}
}
protected virtual bool IsSamgeType(EntityColumnInfo ec, DbColumnInfo dc)
protected virtual bool IsNoSamgeType(EntityColumnInfo ec, DbColumnInfo dc)
{
if (!string.IsNullOrEmpty(ec.DataType))
{
@ -365,6 +365,22 @@ namespace SqlSugar
{
return false;
}
if (properyTypeName?.ToLower() == "varchar" && dataType?.ToLower() == "string")
{
return false;
}
if (properyTypeName?.ToLower() == "number" && dataType?.ToLower() == "decimal")
{
return false;
}
if (properyTypeName?.ToLower() == "int" && dataType?.ToLower() == "decimal"&&dc.Length==22&&dc.Scale==0&&this.Context.CurrentConnectionConfig.DbType==DbType.Oracle)
{
return false;
}
if (properyTypeName?.ToLower() == "date" && dataType?.ToLower() == "datetime")
{
return false;
}
return properyTypeName != dataType;
}
private static string GetType(string name)

Loading…
Cancel
Save