- 修复 AOP 优先级最高 Aop.ConfigEntity 无法获取 ModifyIndexResult 的问题;

This commit is contained in:
28810
2025-09-28 14:38:35 +08:00
parent 8a8b730ac8
commit 2e6be8b509
2 changed files with 13 additions and 4 deletions

View File

@@ -138,7 +138,7 @@ namespace FreeSql.Aop
/// <summary> /// <summary>
/// 索引配置 /// 索引配置
/// </summary> /// </summary>
public List<IndexAttribute> ModifyIndexResult { get; } public List<IndexAttribute> ModifyIndexResult { get; internal set; }
} }
public class ConfigEntityPropertyEventArgs : EventArgs public class ConfigEntityPropertyEventArgs : EventArgs
{ {

View File

@@ -175,6 +175,13 @@ namespace FreeSql.Internal
case MappingPriorityType.Aop: case MappingPriorityType.Aop:
if (_orm.Aop.ConfigEntityHandler != null) if (_orm.Aop.ConfigEntityHandler != null)
{ {
var aopeIndexsPriorityTypes = new List<MappingPriorityType>();
foreach (var aipt in _mappingPriorityTypes)
{
if (aipt == MappingPriorityType.Aop) break;
else aopeIndexsPriorityTypes.Add(aipt);
}
var aopeIndexs = GetEntityIndexAttribute(type, aopeIndexsPriorityTypes.ToArray());
var aope = new Aop.ConfigEntityEventArgs(type) var aope = new Aop.ConfigEntityEventArgs(type)
{ {
ModifyResult = new TableAttribute ModifyResult = new TableAttribute
@@ -183,7 +190,8 @@ namespace FreeSql.Internal
OldName = attr.OldName, OldName = attr.OldName,
_DisableSyncStructure = attr._DisableSyncStructure, _DisableSyncStructure = attr._DisableSyncStructure,
AsTable = attr.AsTable AsTable = attr.AsTable
} },
ModifyIndexResult = aopeIndexs.ToList()
}; };
_orm.Aop.ConfigEntityHandler(_orm, aope); _orm.Aop.ConfigEntityHandler(_orm, aope);
var tryattr = aope.ModifyResult; var tryattr = aope.ModifyResult;
@@ -412,10 +420,11 @@ namespace FreeSql.Internal
if (attr.ManyToMany != null) ret = attr; if (attr.ManyToMany != null) ret = attr;
return ret; return ret;
} }
public IndexAttribute[] GetEntityIndexAttribute(Type type) public IndexAttribute[] GetEntityIndexAttribute(Type type, MappingPriorityType[] mappingPriorityTypes)
{ {
if (mappingPriorityTypes == null) mappingPriorityTypes = _mappingPriorityTypes;
var ret = new Dictionary<string, IndexAttribute>(); var ret = new Dictionary<string, IndexAttribute>();
foreach (var mp in _mappingPriorityTypes) foreach (var mp in mappingPriorityTypes)
{ {
switch (mp) switch (mp)
{ {