mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Oracle CodeFirst
This commit is contained in:
parent
22db10c9c0
commit
5853196116
@ -38,7 +38,7 @@ namespace OrmTest.Demo
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = Config.ConnectionString,
|
||||
DbType = DbType.SqlServer,
|
||||
DbType = DbType.Oracle,
|
||||
IsAutoCloseConnection = true,
|
||||
InitKeyType = InitKeyType.Attribute
|
||||
});
|
||||
@ -47,7 +47,7 @@ namespace OrmTest.Demo
|
||||
//db.CodeFirst.BackupTable().InitTables(typeof(CodeTable),typeof(CodeTable2));
|
||||
|
||||
//No backup table
|
||||
db.CodeFirst.InitTables(typeof(CodeTable),typeof(CodeTable2));
|
||||
db.CodeFirst.InitTables(typeof(CodeTable));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,12 +41,12 @@ namespace OrmTest
|
||||
OrmTest.Demo.Query.Init();
|
||||
OrmTest.Demo.Insert.Init();
|
||||
// OrmTest.Demo.Delete.Init();
|
||||
OrmTest.Demo.Update.Init();
|
||||
OrmTest.Demo.DbFirst.Init();
|
||||
OrmTest.Demo.JoinSql.Init();
|
||||
OrmTest.Demo.Filter.Init();
|
||||
OrmTest.Demo.ComplexModel.Init();
|
||||
//OrmTest.Demo.CodeFirst.Init();
|
||||
//OrmTest.Demo.Update.Init();
|
||||
//OrmTest.Demo.DbFirst.Init();
|
||||
//OrmTest.Demo.JoinSql.Init();
|
||||
//OrmTest.Demo.Filter.Init();
|
||||
//OrmTest.Demo.ComplexModel.Init();
|
||||
OrmTest.Demo.CodeFirst.Init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,27 @@ namespace SqlSugar
|
||||
{
|
||||
public class OracleCodeFirst : CodeFirstProvider
|
||||
{
|
||||
public OracleCodeFirst()
|
||||
protected override void GetDbType(EntityColumnInfo item, Type propertyType, DbColumnInfo result)
|
||||
{
|
||||
throw new Exception("Oracle该功能还未测试");
|
||||
if (!string.IsNullOrEmpty(item.DataType))
|
||||
{
|
||||
result.DataType = item.DataType;
|
||||
}
|
||||
else if (propertyType.IsEnum())
|
||||
{
|
||||
result.DataType = this.Context.Ado.DbBind.GetDbTypeName(item.Length > 9 ? UtilConstants.LongType.Name : UtilConstants.IntType.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (propertyType.Name.Equals("Guid", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
result.DataType = this.Context.Ado.DbBind.GetDbTypeName(UtilConstants.StringType.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.DataType = this.Context.Ado.DbBind.GetDbTypeName(propertyType.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return "IDENTITY(1,1)";
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@ -319,7 +319,27 @@ namespace SqlSugar
|
||||
|
||||
public override bool CreateTable(string tableName, List<DbColumnInfo> columns, bool isCreatePrimaryKey = true)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (columns.HasValue())
|
||||
{
|
||||
foreach (var item in columns)
|
||||
{
|
||||
if (item.DbColumnName.Equals("GUID", StringComparison.CurrentCultureIgnoreCase) && item.Length == 0)
|
||||
{
|
||||
item.Length = 50;
|
||||
}
|
||||
}
|
||||
}
|
||||
string sql = GetCreateTableSql(tableName, columns);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
if (isCreatePrimaryKey)
|
||||
{
|
||||
var pkColumns = columns.Where(it => it.IsPrimarykey).ToList();
|
||||
foreach (var item in pkColumns)
|
||||
{
|
||||
this.Context.DbMaintenance.AddPrimaryKey(tableName, item.DbColumnName);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user