mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
Update Gbase dbfirst
This commit is contained in:
parent
5b79f9badb
commit
92e9feb305
@ -70,14 +70,8 @@ namespace OrmTest
|
|||||||
//db.DbMaintenance.CreateDatabase();
|
//db.DbMaintenance.CreateDatabase();
|
||||||
|
|
||||||
//Use db query
|
//Use db query
|
||||||
var dt = db.Ado.GetDataTable(@"
|
|
||||||
select
|
var dt2= db.Ado.GetDataReader("select * from order").GetSchemaTable();
|
||||||
trim(a.tabname) as name,
|
|
||||||
trim(b.comments) as comment
|
|
||||||
from systables a
|
|
||||||
left join syscomments b on b.tabname = a.tabname
|
|
||||||
where a.tabtype in ('T', 'V') and not (a.tabname like 'sys%') AND a.tabname <>'dual'");
|
|
||||||
|
|
||||||
|
|
||||||
//Create tables
|
//Create tables
|
||||||
db.CodeFirst.InitTables(typeof(OrderItem),typeof(Order));
|
db.CodeFirst.InitTables(typeof(OrderItem),typeof(Order));
|
||||||
|
@ -14,6 +14,7 @@ namespace GbaseTest
|
|||||||
Demo2_Updateable.Init();
|
Demo2_Updateable.Init();
|
||||||
Demo7_Ado.Init();
|
Demo7_Ado.Init();
|
||||||
DemoE_CodeFirst.Init();
|
DemoE_CodeFirst.Init();
|
||||||
|
DemoD_DbFirst.Init();
|
||||||
Console.WriteLine("Hello World!");
|
Console.WriteLine("Hello World!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Data.Odbc;
|
||||||
namespace SqlSugar.GBase
|
namespace SqlSugar.GBase
|
||||||
{
|
{
|
||||||
public class GBaseDbMaintenance : DbMaintenanceProvider
|
public class GBaseDbMaintenance : DbMaintenanceProvider
|
||||||
@ -320,6 +320,55 @@ where a.tabtype in ('V') and not (a.tabname like 'sys%') AND a.tabname <>'dual'
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
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);
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
||||||
|
{
|
||||||
|
string sql = "select * /* " + Guid.NewGuid() + " */ from " + SqlBuilder.GetTranslationTableName(tableName) + " WHERE 1=2 ";
|
||||||
|
this.Context.Utilities.RemoveCache<List<DbColumnInfo>>("DbMaintenanceProvider.GetFieldComment." + tableName);
|
||||||
|
this.Context.Utilities.RemoveCache<List<string>>("DbMaintenanceProvider.GetPrimaryKeyByTableNames." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower());
|
||||||
|
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||||
|
this.Context.Ado.IsEnableLogEvent = false;
|
||||||
|
using (var reader = this.Context.Ado.GetDataReader(sql))
|
||||||
|
{
|
||||||
|
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
|
||||||
|
List<DbColumnInfo> result = new List<DbColumnInfo>();
|
||||||
|
var schemaTable = reader.GetSchemaTable();
|
||||||
|
int i = 0;
|
||||||
|
foreach (System.Data.DataRow row in schemaTable.Rows)
|
||||||
|
{
|
||||||
|
DbColumnInfo column = new DbColumnInfo()
|
||||||
|
{
|
||||||
|
TableName = tableName,
|
||||||
|
DataType = row["DataType"].ToString().Replace("System.", "").Trim(),
|
||||||
|
IsNullable = (bool)row["AllowDBNull"],
|
||||||
|
IsIdentity = (bool)row["IsAutoIncrement"],
|
||||||
|
// ColumnDescription = GetFieldComment(tableName, row["ColumnName"].ToString()),
|
||||||
|
DbColumnName = row["ColumnName"].ToString(),
|
||||||
|
//DefaultValue = row["defaultValue"].ToString(),
|
||||||
|
IsPrimarykey = i==0,//no support get pk
|
||||||
|
Length = row["ColumnSize"].ObjToInt(),
|
||||||
|
Scale = row["numericscale"].ObjToInt()
|
||||||
|
};
|
||||||
|
++i;
|
||||||
|
result.Add(column);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
protected override string GetCreateTableSql(string tableName, List<DbColumnInfo> columns)
|
protected override string GetCreateTableSql(string tableName, List<DbColumnInfo> columns)
|
||||||
{
|
{
|
||||||
List<string> columnArray = new List<string>();
|
List<string> columnArray = new List<string>();
|
||||||
@ -413,12 +462,12 @@ where a.tabtype in ('V') and not (a.tabname like 'sys%') AND a.tabname <>'dual'
|
|||||||
//}
|
//}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName, bool isCache = true)
|
//public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName, bool isCache = true)
|
||||||
{
|
//{
|
||||||
tableName = SqlBuilder.GetNoTranslationColumnName(tableName);
|
// tableName = SqlBuilder.GetNoTranslationColumnName(tableName);
|
||||||
var result= base.GetColumnInfosByTableName(tableName, isCache);
|
// var result= base.GetColumnInfosByTableName(tableName, isCache);
|
||||||
return result;
|
// return result;
|
||||||
}
|
//}
|
||||||
public override bool RenameColumn(string tableName, string oldColumnName, string newColumnName)
|
public override bool RenameColumn(string tableName, string oldColumnName, string newColumnName)
|
||||||
{
|
{
|
||||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||||
|
Loading…
Reference in New Issue
Block a user