mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-14 04:10:56 +08:00
ZeroDbContext.LoadSchemaFromDatabase("table1")
This commit is contained in:
@@ -264,23 +264,24 @@ ManyToMany 级联删除中间表(注意不删除外部根)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从数据库中加载 TableDescriptor 描述<para></para>
|
||||
/// 从数据库中加载<para></para>
|
||||
/// - 不支持 Navigates<para></para>
|
||||
/// - 不支持 Indexes IndexMethod<para></para>
|
||||
/// - 暂支持 SqlServer/MySql decimal(10,2)(其他数据库需实现对应 IDbFirst)
|
||||
/// </summary>
|
||||
static TableDescriptor LoadTableDescriptor(IFreeSql orm, string tableName)
|
||||
public TableDescriptor LoadSchemaFromDatabase(string tableName)
|
||||
{
|
||||
var dbinfo = orm.DbFirst.GetTableByName(tableName, true);
|
||||
if (_tables.Any(a => string.Compare(a.DbName, tableName, true) == 0)) return;
|
||||
var dbinfo = _orm.DbFirst.GetTableByName(tableName, true);
|
||||
if (dbinfo == null) throw new Exception($"表“{tableName}”不存在");
|
||||
var tb = new TableDescriptor
|
||||
var schema = new TableDescriptor
|
||||
{
|
||||
Comment = dbinfo.Comment,
|
||||
DbName = dbinfo.Name,
|
||||
Name = dbinfo.Name,
|
||||
DisableSyncStructure = false,
|
||||
};
|
||||
tb.Columns.AddRange(dbinfo.Columns.Select(a => new TableDescriptor.ColumnDescriptor
|
||||
schema.Columns.AddRange(dbinfo.Columns.Select(a => new TableDescriptor.ColumnDescriptor
|
||||
{
|
||||
Name = a.Name,
|
||||
DbType = a.DbTypeText,
|
||||
@@ -296,13 +297,14 @@ ManyToMany 级联删除中间表(注意不删除外部根)
|
||||
Scale = a.Scale,
|
||||
Comment = a.Comment,
|
||||
}));
|
||||
tb.Indexes.AddRange(dbinfo.Indexes.Select(a => new TableDescriptor.IndexDescriptor
|
||||
schema.Indexes.AddRange(dbinfo.Indexes.Select(a => new TableDescriptor.IndexDescriptor
|
||||
{
|
||||
Name = a.Name,
|
||||
IsUnique = a.IsUnique,
|
||||
Fields = string.Join(",", a.Columns.Select(b => b.Column)),
|
||||
}));
|
||||
return tb;
|
||||
_tables.AddRange(ValidateSchemaToInfoInternal(_orm, new[] { schema }));
|
||||
return schema;
|
||||
}
|
||||
|
||||
public ZeroDbContext WithTransaction(DbTransaction value)
|
||||
|
||||
Reference in New Issue
Block a user