- 优化 Aop.ConfigEntity 使用 ModifyResult 访问最新的设置;#1247

This commit is contained in:
2881099 2022-09-18 17:56:55 +08:00
parent 832f8a21a6
commit ef371af480
2 changed files with 37 additions and 4 deletions

View File

@ -134,7 +134,7 @@ namespace FreeSql.Aop
/// <summary> /// <summary>
/// 实体配置 /// 实体配置
/// </summary> /// </summary>
public TableAttribute ModifyResult { get; } public TableAttribute ModifyResult { get; internal set; }
/// <summary> /// <summary>
/// 索引配置 /// 索引配置
/// </summary> /// </summary>
@ -160,7 +160,7 @@ namespace FreeSql.Aop
/// <summary> /// <summary>
/// 实体的属性配置 /// 实体的属性配置
/// </summary> /// </summary>
public ColumnAttribute ModifyResult { get; } public ColumnAttribute ModifyResult { get; internal set; }
} }
#endregion #endregion

View File

@ -123,7 +123,16 @@ namespace FreeSql.Internal
case MappingPriorityType.Aop: case MappingPriorityType.Aop:
if (_orm.Aop.ConfigEntityHandler != null) if (_orm.Aop.ConfigEntityHandler != null)
{ {
var aope = new Aop.ConfigEntityEventArgs(type); var aope = new Aop.ConfigEntityEventArgs(type)
{
ModifyResult = new TableAttribute
{
Name = attr.Name,
OldName = attr.OldName,
_DisableSyncStructure = attr._DisableSyncStructure,
AsTable = attr.AsTable
}
};
_orm.Aop.ConfigEntityHandler(_orm, aope); _orm.Aop.ConfigEntityHandler(_orm, aope);
var tryattr = aope.ModifyResult; var tryattr = aope.ModifyResult;
if (!string.IsNullOrEmpty(tryattr.Name)) attr.Name = tryattr.Name; if (!string.IsNullOrEmpty(tryattr.Name)) attr.Name = tryattr.Name;
@ -171,7 +180,31 @@ namespace FreeSql.Internal
case MappingPriorityType.Aop: case MappingPriorityType.Aop:
if (_orm.Aop.ConfigEntityPropertyHandler != null) if (_orm.Aop.ConfigEntityPropertyHandler != null)
{ {
var aope = new Aop.ConfigEntityPropertyEventArgs(type, proto); var aope = new Aop.ConfigEntityPropertyEventArgs(type, proto)
{
ModifyResult = new ColumnAttribute
{
Name = attr.Name,
OldName = attr.OldName,
DbType = attr.DbType,
_IsPrimary = attr._IsPrimary,
_IsIdentity = attr._IsIdentity,
_IsNullable = attr._IsNullable,
_IsIgnore = attr._IsIgnore,
_IsVersion = attr._IsVersion,
MapType = attr.MapType,
_Position = attr._Position,
_CanInsert = attr._CanInsert,
_CanUpdate = attr._CanUpdate,
ServerTime = attr.ServerTime,
_StringLength = attr._StringLength,
InsertValueSql = attr.InsertValueSql,
_Precision = attr._Precision,
_Scale = attr._Scale,
RewriteSql = attr.RewriteSql,
RereadSql = attr.RereadSql
}
};
_orm.Aop.ConfigEntityPropertyHandler(_orm, aope); _orm.Aop.ConfigEntityPropertyHandler(_orm, aope);
var tryattr = aope.ModifyResult; var tryattr = aope.ModifyResult;
if (!string.IsNullOrEmpty(tryattr.Name)) attr.Name = tryattr.Name; if (!string.IsNullOrEmpty(tryattr.Name)) attr.Name = tryattr.Name;