diff --git a/AOP.md b/AOP.md index fe38965..18063a0 100644 --- a/AOP.md +++ b/AOP.md @@ -89,6 +89,34 @@ FreeSql 自带迁移功能,那么迁移的 SQL 语句长啥样,你可能会 fsql.Aop.SyncStructureBefore、fsql.Aop.SyncStructureAfter 这两个事件将排上用场。 +## ConfigEntityProperty + +### MySql Enum 映射 + +默认情况 c# 枚举会映射为 MySql Enum 类型,如果想映射为 int 在 FreeSqlBuilder Build 之后执行以下 Aop 统一处理: + +```csharp +fsql.Aop.ConfigEntityProperty += (s, e) => { + if (e.Property.PropertyType.IsEnum) + e.ModifyResult.MapType = typeof(int); +}; +``` + +### 修改 decimal 默认特性 + +因为默认 decimal 只支持 decimal(10,2),范围太小,我们可以全局修改 decimal 类型的支持范围,比如支持 decimal(18,6) + +```csharp +fsql1.Aop.ConfigEntityProperty += (s, e) => +{ + if (e.Property.PropertyType == typeof(decimal)|| e.Property.PropertyType == typeof(decimal?)) + { + e.ModifyResult.Precision = 18; + e.ModifyResult.Scale = 6; + } +}; +``` + ## 自定义实体特性 比如项目内已经使用了其它 orm,如 efcore,这样意味着实体中可能存在 [Key],但它与 FreeSql [Column(IsPrimary = true] 不同。