From cfe2894b9bb48f0efa866f7207cdd0a0c8b4e8fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Sun, 20 Oct 2024 12:42:29 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=E5=B8=A6=E6=9C=89=E5=88=86=E8=A1=A8?= =?UTF-8?q?=E7=AD=96=E7=95=A5=E7=9A=84=E5=AE=9E=E4=BD=93=E7=B1=BB=E4=B8=8D?= =?UTF-8?q?=E5=8F=82=E4=B8=8E=E5=8F=8D=E5=90=91=E5=B7=A5=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XCode/DataAccessLayer/MetaData/IMetaData.cs | 91 ++++++++++----------- XCode/Entity/EntityFactory.cs | 14 ++-- 2 files changed, 51 insertions(+), 54 deletions(-) diff --git a/XCode/DataAccessLayer/MetaData/IMetaData.cs b/XCode/DataAccessLayer/MetaData/IMetaData.cs index f51b658c5..deed5ec47 100644 --- a/XCode/DataAccessLayer/MetaData/IMetaData.cs +++ b/XCode/DataAccessLayer/MetaData/IMetaData.cs @@ -1,50 +1,47 @@ -using System; -using System.Collections.Generic; -using NewLife; +using NewLife; -namespace XCode.DataAccessLayer +namespace XCode.DataAccessLayer; + +/// 数据库元数据接口 +public interface IMetaData : IDisposable2 { - /// 数据库元数据接口 - public interface IMetaData : IDisposable2 - { - #region 属性 - /// 数据库 - IDatabase Database { get; } - - /// 所有元数据集合 - ICollection MetaDataCollections { get; } - - /// 保留关键字 - ICollection ReservedWords { get; } - #endregion - - #region 构架 - /// 取得表模型,正向工程 - /// - IList GetTables(); - - /// - /// 取得所有表名 - /// - /// - IList GetTableNames(); - - /// 设置表模型,检查数据表是否匹配表模型,反向工程 - /// 设置 - /// - void SetTables(Migration setting, params IDataTable[] tables); - - /// 获取数据定义语句 - /// 数据定义模式 - /// 其它信息 - /// 数据定义语句 - String? GetSchemaSQL(DDLSchema schema, params Object?[] values); - - /// 设置数据定义模式 - /// 数据定义模式 - /// 其它信息 - /// - Object? SetSchema(DDLSchema schema, params Object?[] values); - #endregion - } + #region 属性 + /// 数据库 + IDatabase Database { get; } + + /// 所有元数据集合 + ICollection MetaDataCollections { get; } + + /// 保留关键字 + ICollection ReservedWords { get; } + #endregion + + #region 构架 + /// 取得表模型,正向工程 + /// + IList GetTables(); + + /// + /// 取得所有表名 + /// + /// + IList GetTableNames(); + + /// 设置表模型,检查数据表是否匹配表模型,反向工程 + /// 设置 + /// + void SetTables(Migration setting, params IDataTable[] tables); + + /// 获取数据定义语句 + /// 数据定义模式 + /// 其它信息 + /// 数据定义语句 + String? GetSchemaSQL(DDLSchema schema, params Object?[] values); + + /// 设置数据定义模式 + /// 数据定义模式 + /// 其它信息 + /// + Object? SetSchema(DDLSchema schema, params Object?[] values); + #endregion } \ No newline at end of file diff --git a/XCode/Entity/EntityFactory.cs b/XCode/Entity/EntityFactory.cs index a7f42ac6b..51711823f 100644 --- a/XCode/Entity/EntityFactory.cs +++ b/XCode/Entity/EntityFactory.cs @@ -251,19 +251,23 @@ private static void Init(String connName, IList? types, Boolean throwOnErr // 反向工程检查 if (dal.Db.Migration > Migration.Off) { - //var tables = facts.Select(e => e.Table.DataTable).ToArray(); var tables = new List(); foreach (var item in facts) { + // 带有分表策略的实体类不参与反向工程 + if (item.ShardPolicy != null) continue; + if (item.Table.DataTable.Columns.Any(e => e.DataScale.StartsWithIgnoreCase("shard:", "timeShard:"))) continue; + // 克隆一份,防止修改 var table = item.Table.DataTable; table = (table.Clone() as IDataTable)!; - if (/*table != null &&*/ table.TableName != item.TableName) + if (table.TableName != item.TableName) { // 表名去掉前缀 var name = item.TableName; - if (name.Contains(".")) name = name.Substring("."); + var p = name.IndexOf('.'); + if (p > 0) name = name.Substring(p + 1); table.TableName = name; } @@ -276,10 +280,6 @@ private static void Init(String connName, IList? types, Boolean throwOnErr // 实体类初始化数据 foreach (var item in facts) { - //if (item.Default is EntityBase entity) - //{ - // entity.InitData(); - //} item.Session.InitData(); if (span != null) span.Value++;