修复 外部配置实体ConfigEntity 与 延时加载 冲突产生的 bug

This commit is contained in:
28810 2019-03-02 09:45:16 +08:00
parent 8e4d3c03a5
commit a2f4a8bcd8
4 changed files with 11 additions and 6 deletions

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<Version>0.1.5.3</Version> <Version>0.1.6</Version>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql 通用仓库层现实,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description> <Description>FreeSql 通用仓库层现实,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl> <PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<Version>0.1.5</Version> <Version>0.1.6</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>打造 .NETCore 最方便的 ORMDbFirst 与 CodeFirst 混合使用,提供从实体同步数据库,或者从数据库生成实体代码,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description> <Description>打造 .NETCore 最方便的 ORMDbFirst 与 CodeFirst 混合使用,提供从实体同步数据库,或者从数据库生成实体代码,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>

View File

@ -39,7 +39,7 @@ namespace FreeSql.Internal {
var table = dicConfigEntity.GetOrAdd(type, new TableAttribute()); var table = dicConfigEntity.GetOrAdd(type, new TableAttribute());
var fluent = new TableFluent<T>(table); var fluent = new TableFluent<T>(table);
entity.Invoke(fluent); entity.Invoke(fluent);
Utils.GetTableByEntity(type, this, true); //update cache Utils.RemoveTableByEntity(type, this); //remove cache
return _orm.CodeFirst; return _orm.CodeFirst;
} }
internal ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) { internal ICodeFirst ConfigEntity(Type type, Action<TableFluent> entity) {
@ -47,7 +47,7 @@ namespace FreeSql.Internal {
var table = dicConfigEntity.GetOrAdd(type, new TableAttribute()); var table = dicConfigEntity.GetOrAdd(type, new TableAttribute());
var fluent = new TableFluent(type, table); var fluent = new TableFluent(type, table);
entity.Invoke(fluent); entity.Invoke(fluent);
Utils.GetTableByEntity(type, this, true); //update cache Utils.RemoveTableByEntity(type, this); //remove cache
return _orm.CodeFirst; return _orm.CodeFirst;
} }
internal TableAttribute GetConfigEntity(Type type) { internal TableAttribute GetConfigEntity(Type type) {

View File

@ -24,10 +24,15 @@ namespace FreeSql.Internal {
class Utils { class Utils {
static ConcurrentDictionary<string, ConcurrentDictionary<Type, TableInfo>> _cacheGetTableByEntity = new ConcurrentDictionary<string, ConcurrentDictionary<Type, TableInfo>>(); static ConcurrentDictionary<string, ConcurrentDictionary<Type, TableInfo>> _cacheGetTableByEntity = new ConcurrentDictionary<string, ConcurrentDictionary<Type, TableInfo>>();
internal static TableInfo GetTableByEntity(Type entity, CommonUtils common, bool isReCache = false) { internal static void RemoveTableByEntity(Type entity, CommonUtils common) {
if (entity.FullName.StartsWith("<>f__AnonymousType")) return;
var tbc = _cacheGetTableByEntity.GetOrAdd(common.DbName, k1 => new ConcurrentDictionary<Type, TableInfo>()); //区分数据库类型缓存
tbc.TryRemove(entity, out var trytb);
}
internal static TableInfo GetTableByEntity(Type entity, CommonUtils common) {
if (entity.FullName.StartsWith("<>f__AnonymousType")) return null; if (entity.FullName.StartsWith("<>f__AnonymousType")) return null;
var tbc = _cacheGetTableByEntity.GetOrAdd(common.DbName, k1 => new ConcurrentDictionary<Type, TableInfo>()); //区分数据库类型缓存 var tbc = _cacheGetTableByEntity.GetOrAdd(common.DbName, k1 => new ConcurrentDictionary<Type, TableInfo>()); //区分数据库类型缓存
if (isReCache == false && tbc.TryGetValue(entity, out var trytb)) return trytb; if (tbc.TryGetValue(entity, out var trytb)) return trytb;
if (common.CodeFirst.GetDbInfo(entity) != null) return null; if (common.CodeFirst.GetDbInfo(entity) != null) return null;
var tbattr = common.GetEntityTableAttribute(entity); var tbattr = common.GetEntityTableAttribute(entity);