diff --git a/Falcon.SugarApi/DatabaseDefinitions/DisableDeleteColummAttribute.cs b/Falcon.SugarApi/DatabaseDefinitions/DisableDeleteColummAttribute.cs new file mode 100644 index 0000000..2e0a00a --- /dev/null +++ b/Falcon.SugarApi/DatabaseDefinitions/DisableDeleteColummAttribute.cs @@ -0,0 +1,10 @@ +using System; + +namespace Falcon.SugarApi.DatabaseDefinitions +{ + /// <summary> + /// 禁止删除表格的列 + /// </summary> + [AttributeUsage(AttributeTargets.Class,AllowMultiple = false,Inherited = true)] + public class DisableDeleteColummAttribute:Attribute { } +} diff --git a/Falcon.SugarApi/DatabaseDefinitions/DisableUpdateAttribute.cs b/Falcon.SugarApi/DatabaseDefinitions/DisableUpdateAttribute.cs new file mode 100644 index 0000000..d02d380 --- /dev/null +++ b/Falcon.SugarApi/DatabaseDefinitions/DisableUpdateAttribute.cs @@ -0,0 +1,10 @@ +using System; + +namespace Falcon.SugarApi.DatabaseDefinitions +{ + /// <summary> + /// 禁止更新表结构 + /// </summary> + [AttributeUsage(AttributeTargets.Class,AllowMultiple = false,Inherited = true)] + public class DisableUpdateAttribute:Attribute { } +} diff --git a/Falcon.SugarApi/DatabaseDefinitions/EntityServices/DisableDeleteColummService.cs b/Falcon.SugarApi/DatabaseDefinitions/EntityServices/DisableDeleteColummService.cs new file mode 100644 index 0000000..b278c47 --- /dev/null +++ b/Falcon.SugarApi/DatabaseDefinitions/EntityServices/DisableDeleteColummService.cs @@ -0,0 +1,18 @@ +using SqlSugar; +using System; + +namespace Falcon.SugarApi.DatabaseDefinitions.EntityServices +{ + /// <summary> + /// 设置禁止删除列服务 + /// </summary> + public class DisableDeleteColummService:IEntityTableServices + { + /// <inheritdoc/> + public void SetupTable(Type t,EntityInfo e) { + if(t.TryGetAttribute<DisableDeleteColummAttribute>(out var _)) { + e.IsDisabledDelete = true; + } + } + } +} diff --git a/Falcon.SugarApi/DatabaseDefinitions/EntityServices/DisableUpdateAllService.cs b/Falcon.SugarApi/DatabaseDefinitions/EntityServices/DisableUpdateAllService.cs new file mode 100644 index 0000000..844c9b2 --- /dev/null +++ b/Falcon.SugarApi/DatabaseDefinitions/EntityServices/DisableUpdateAllService.cs @@ -0,0 +1,18 @@ +using SqlSugar; +using System; + +namespace Falcon.SugarApi.DatabaseDefinitions.EntityServices +{ + /// <summary> + /// 设置禁止升级表架构服务 + /// </summary> + public class DisableUpdateAllService:IEntityTableServices + { + /// <inheritdoc/> + public void SetupTable(Type t,EntityInfo e) { + if(t.TryGetAttribute<DisableUpdateAttribute>(out var _)) { + e.IsDisabledUpdateAll = true; + } + } + } +} diff --git a/Falcon.SugarApi/DatabaseDefinitions/EntityServices/TableNameTableService.cs b/Falcon.SugarApi/DatabaseDefinitions/EntityServices/TableNameTableService.cs index 5ffb647..83cf694 100644 --- a/Falcon.SugarApi/DatabaseDefinitions/EntityServices/TableNameTableService.cs +++ b/Falcon.SugarApi/DatabaseDefinitions/EntityServices/TableNameTableService.cs @@ -7,11 +7,11 @@ namespace Falcon.SugarApi.DatabaseDefinitions.EntityServices /// <summary> /// 设置表名服务 /// </summary> - public class TableNameTableService : IEntityTableServices + public class TableNameTableService:IEntityTableServices { /// <inheritdoc/> - public void SetupTable(Type t, EntityInfo e) { - if (t.TryGetAttribute<TableAttribute>(out var tn)) { + public void SetupTable(Type t,EntityInfo e) { + if(t.TryGetAttribute<TableAttribute>(out var tn)) { e.DbTableName = tn.Name; } } diff --git a/Falcon.SugarApi/DatabaseManager/DbContextBase.cs b/Falcon.SugarApi/DatabaseManager/DbContextBase.cs index 10c810c..b9102de 100644 --- a/Falcon.SugarApi/DatabaseManager/DbContextBase.cs +++ b/Falcon.SugarApi/DatabaseManager/DbContextBase.cs @@ -42,6 +42,8 @@ namespace Falcon.SugarApi.DatabaseManager var ces = config.ConfigureExternalServices; ces.EntityNameService = (t,e) => { new TableNameTableService().SetupTable(t,e); + new DisableDeleteColummService().SetupTable(t,e); + new DisableUpdateAllService().SetupTable(t,e); }; ces.EntityService = (p,c) => { new SetupKeyColumnServices().SetupColumn(p,c);