mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
- 优化 FluentApi 继承关系可直接 ConfigEntity<BaseEntity> 生效;#1144
This commit is contained in:
@ -196,27 +196,38 @@ namespace FreeSql.Internal
|
||||
}
|
||||
break;
|
||||
case MappingPriorityType.FluentApi:
|
||||
if (dicConfigEntity.TryGetValue(type, out var trytb) && trytb._columns.TryGetValue(proto.Name, out var trycol))
|
||||
var baseTypes = new List<Type>();
|
||||
var baseType = type;
|
||||
while (baseType != typeof(object) && baseType != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(trycol.Name)) attr.Name = trycol.Name;
|
||||
if (!string.IsNullOrEmpty(trycol.OldName)) attr.OldName = trycol.OldName;
|
||||
if (!string.IsNullOrEmpty(trycol.DbType)) attr.DbType = trycol.DbType;
|
||||
if (trycol._IsPrimary != null) attr._IsPrimary = trycol.IsPrimary;
|
||||
if (trycol._IsIdentity != null) attr._IsIdentity = trycol.IsIdentity;
|
||||
if (trycol._IsNullable != null) attr._IsNullable = trycol.IsNullable;
|
||||
if (trycol._IsIgnore != null) attr._IsIgnore = trycol.IsIgnore;
|
||||
if (trycol._IsVersion != null) attr._IsVersion = trycol.IsVersion;
|
||||
if (trycol.MapType != null) attr.MapType = trycol.MapType;
|
||||
if (trycol._Position != null) attr._Position = trycol.Position;
|
||||
if (trycol._CanInsert != null) attr._CanInsert = trycol.CanInsert;
|
||||
if (trycol._CanUpdate != null) attr._CanUpdate = trycol.CanUpdate;
|
||||
if (trycol.ServerTime != DateTimeKind.Unspecified) attr.ServerTime = trycol.ServerTime;
|
||||
if (trycol._StringLength != null) attr.StringLength = trycol.StringLength;
|
||||
if (!string.IsNullOrEmpty(trycol.InsertValueSql)) attr.InsertValueSql = trycol.InsertValueSql;
|
||||
if (trycol._Precision != null) attr.Precision = trycol.Precision;
|
||||
if (trycol._Scale != null) attr.Scale = trycol.Scale;
|
||||
if (!string.IsNullOrEmpty(trycol.RewriteSql)) attr.RewriteSql = trycol.RewriteSql;
|
||||
if (!string.IsNullOrEmpty(trycol.RereadSql)) attr.RereadSql = trycol.RereadSql;
|
||||
baseTypes.Add(baseType);
|
||||
baseType = baseType.BaseType;
|
||||
}
|
||||
for (var a = baseTypes.Count - 1; a >= 0; a--)
|
||||
{
|
||||
var entityType = baseTypes[a];
|
||||
if (dicConfigEntity.TryGetValue(entityType, out var trytb) && trytb._columns.TryGetValue(proto.Name, out var trycol))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(trycol.Name)) attr.Name = trycol.Name;
|
||||
if (!string.IsNullOrEmpty(trycol.OldName)) attr.OldName = trycol.OldName;
|
||||
if (!string.IsNullOrEmpty(trycol.DbType)) attr.DbType = trycol.DbType;
|
||||
if (trycol._IsPrimary != null) attr._IsPrimary = trycol.IsPrimary;
|
||||
if (trycol._IsIdentity != null) attr._IsIdentity = trycol.IsIdentity;
|
||||
if (trycol._IsNullable != null) attr._IsNullable = trycol.IsNullable;
|
||||
if (trycol._IsIgnore != null) attr._IsIgnore = trycol.IsIgnore;
|
||||
if (trycol._IsVersion != null) attr._IsVersion = trycol.IsVersion;
|
||||
if (trycol.MapType != null) attr.MapType = trycol.MapType;
|
||||
if (trycol._Position != null) attr._Position = trycol.Position;
|
||||
if (trycol._CanInsert != null) attr._CanInsert = trycol.CanInsert;
|
||||
if (trycol._CanUpdate != null) attr._CanUpdate = trycol.CanUpdate;
|
||||
if (trycol.ServerTime != DateTimeKind.Unspecified) attr.ServerTime = trycol.ServerTime;
|
||||
if (trycol._StringLength != null) attr.StringLength = trycol.StringLength;
|
||||
if (!string.IsNullOrEmpty(trycol.InsertValueSql)) attr.InsertValueSql = trycol.InsertValueSql;
|
||||
if (trycol._Precision != null) attr.Precision = trycol.Precision;
|
||||
if (trycol._Scale != null) attr.Scale = trycol.Scale;
|
||||
if (!string.IsNullOrEmpty(trycol.RewriteSql)) attr.RewriteSql = trycol.RewriteSql;
|
||||
if (!string.IsNullOrEmpty(trycol.RereadSql)) attr.RereadSql = trycol.RereadSql;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MappingPriorityType.Attribute:
|
||||
|
@ -28,6 +28,9 @@ namespace FreeSql.Internal
|
||||
) return;
|
||||
var tbc = _cacheGetTableByEntity.GetOrAdd(common._orm.Ado.DataType, k1 => new ConcurrentDictionary<Type, TableInfo>()); //区分数据库类型缓存
|
||||
if (tbc.TryRemove(entity, out var trytb) && trytb?.TypeLazy != null) tbc.TryRemove(trytb.TypeLazy, out var trylz);
|
||||
var reltypes = tbc.Keys.Where(a => entity.IsAssignableFrom(a)).ToArray();
|
||||
foreach (var reltype in reltypes)
|
||||
if (tbc.TryRemove(reltype, out trytb) && trytb?.TypeLazy != null) tbc.TryRemove(trytb.TypeLazy, out var trylz);
|
||||
}
|
||||
internal static TableInfo GetTableByEntity(Type entity, CommonUtils common)
|
||||
{
|
||||
|
Reference in New Issue
Block a user