mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
- 修复 postgresql 12 移除 pg_attrdef.adsrc 列,导致 CodeFirst 方法失败的 bug;
- 增加 Aop.ConfigEntity 属性 ModifyIndexResult 现实 IndexAttribute 的设置;
This commit is contained in:
@ -2185,6 +2185,11 @@
|
||||
实体配置
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.ConfigEntityEventArgs.ModifyIndexResult">
|
||||
<summary>
|
||||
索引配置
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.ConfigEntityPropertyEventArgs.EntityType">
|
||||
<summary>
|
||||
实体类型
|
||||
|
@ -115,6 +115,7 @@ namespace FreeSql.Aop
|
||||
{
|
||||
this.EntityType = entityType;
|
||||
this.ModifyResult = new TableAttribute();
|
||||
this.ModifyIndexResult = new List<IndexAttribute>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -125,6 +126,10 @@ namespace FreeSql.Aop
|
||||
/// 实体配置
|
||||
/// </summary>
|
||||
public TableAttribute ModifyResult { get; }
|
||||
/// <summary>
|
||||
/// 索引配置
|
||||
/// </summary>
|
||||
public List<IndexAttribute> ModifyIndexResult { get; }
|
||||
}
|
||||
public class ConfigEntityPropertyEventArgs : EventArgs
|
||||
{
|
||||
|
@ -87,7 +87,6 @@ namespace FreeSql.Internal
|
||||
if (!string.IsNullOrEmpty(trytb.OldName)) attr.OldName = trytb.OldName;
|
||||
if (!string.IsNullOrEmpty(trytb.SelectFilter)) attr.SelectFilter = trytb.SelectFilter;
|
||||
if (trytb._DisableSyncStructure != null) attr._DisableSyncStructure = trytb.DisableSyncStructure;
|
||||
|
||||
}
|
||||
var attrs = type.GetCustomAttributes(typeof(TableAttribute), false);
|
||||
foreach (var tryattrobj in attrs)
|
||||
@ -190,24 +189,37 @@ namespace FreeSql.Internal
|
||||
}
|
||||
public IndexAttribute[] GetEntityIndexAttribute(Type type)
|
||||
{
|
||||
var ret = new Dictionary<string, IndexAttribute>(); ;
|
||||
var ret = new Dictionary<string, IndexAttribute>();
|
||||
if (_orm.Aop.ConfigEntity != null)
|
||||
{
|
||||
var aope = new Aop.ConfigEntityEventArgs(type);
|
||||
_orm.Aop.ConfigEntity(_orm, aope);
|
||||
foreach (var idxattr in aope.ModifyIndexResult)
|
||||
if (!string.IsNullOrEmpty(idxattr.Name) && !string.IsNullOrEmpty(idxattr.Fields))
|
||||
{
|
||||
if (ret.ContainsKey(idxattr.Name)) ret.Remove(idxattr.Name);
|
||||
ret.Add(idxattr.Name, new IndexAttribute(idxattr.Name, idxattr.Fields) { _IsUnique = idxattr._IsUnique });
|
||||
}
|
||||
}
|
||||
if (dicConfigEntity.TryGetValue(type, out var trytb))
|
||||
{
|
||||
foreach (var idxattr in trytb._indexs.Values)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(idxattr.Name) && !string.IsNullOrEmpty(idxattr.Fields))
|
||||
{
|
||||
if (ret.ContainsKey(idxattr.Name)) ret.Remove(idxattr.Name);
|
||||
ret.Add(idxattr.Name, new IndexAttribute(idxattr.Name, idxattr.Fields) { _IsUnique = idxattr._IsUnique });
|
||||
}
|
||||
}
|
||||
}
|
||||
var attrs = type.GetCustomAttributes(typeof(IndexAttribute), true);
|
||||
foreach (var tryattrobj in attrs)
|
||||
{
|
||||
var idxattr = tryattrobj as IndexAttribute;
|
||||
if (idxattr == null) continue;
|
||||
if (string.IsNullOrEmpty(idxattr.Name)) continue;
|
||||
if (string.IsNullOrEmpty(idxattr.Fields)) continue;
|
||||
if (ret.ContainsKey(idxattr.Name)) ret.Remove(idxattr.Name);
|
||||
ret.Add(idxattr.Name, new IndexAttribute(idxattr.Name, idxattr.Fields) { _IsUnique = idxattr._IsUnique });
|
||||
if (!string.IsNullOrEmpty(idxattr.Name) && !string.IsNullOrEmpty(idxattr.Fields))
|
||||
{
|
||||
if (ret.ContainsKey(idxattr.Name)) ret.Remove(idxattr.Name);
|
||||
ret.Add(idxattr.Name, new IndexAttribute(idxattr.Name, idxattr.Fields) { _IsUnique = idxattr._IsUnique });
|
||||
}
|
||||
}
|
||||
return ret.Values.ToArray();
|
||||
}
|
||||
|
Reference in New Issue
Block a user