向FreeSqlBuilder 添加 表信息映射工厂方法

This commit is contained in:
hyzx86 2023-09-27 01:03:14 +08:00
parent 456c09152c
commit be5b2cc044

View File

@ -11,6 +11,7 @@ using System.Linq.Expressions;
using System.Runtime; using System.Runtime;
using FreeSql.Internal.Model.Interface; using FreeSql.Internal.Model.Interface;
using System.Threading; using System.Threading;
using FreeSql.Internal.Model;
namespace FreeSql namespace FreeSql
{ {
@ -50,6 +51,18 @@ namespace FreeSql
_providerType = providerType; _providerType = providerType;
return this; return this;
} }
/// <summary>
/// 用于指定自定义实现TableEntiy 的缓存集合
/// 解决多实例下相同类型映射到不同表的问题
/// </summary>
/// <param name="factory"></param>
/// <returns></returns>
public FreeSqlBuilder UseCustomTableEntityCacheFactory(Func<ConcurrentDictionary<DataType, ConcurrentDictionary<Type, TableInfo>>> factory)
{
Utils.ChacheTableEntityFactory = factory;
return this;
}
/// <summary> /// <summary>
/// 使用原始连接池ado.net、odbc、oledb<para></para> /// 使用原始连接池ado.net、odbc、oledb<para></para>
/// 默认false<para></para> /// 默认false<para></para>
@ -63,7 +76,7 @@ namespace FreeSql
/// <returns></returns> /// <returns></returns>
public FreeSqlBuilder UseAdoConnectionPool(bool value) public FreeSqlBuilder UseAdoConnectionPool(bool value)
{ {
_isAdoConnectionPool = value ; _isAdoConnectionPool = value;
return this; return this;
} }
/// <summary> /// <summary>
@ -577,7 +590,8 @@ namespace FreeSql
{ {
FreeSql.Internal.Utils.GetDataReaderValueBlockExpressionSwitchTypeFullName.Add((LabelTarget returnTarget, Expression valueExp, Type type2) => FreeSql.Internal.Utils.GetDataReaderValueBlockExpressionSwitchTypeFullName.Add((LabelTarget returnTarget, Expression valueExp, Type type2) =>
{ {
if (FreeSql.Internal.Utils.TypeHandlers.TryGetValue(type2, out var typeHandler)) { if (FreeSql.Internal.Utils.TypeHandlers.TryGetValue(type2, out var typeHandler))
{
var valueExpRet = Expression.Call( var valueExpRet = Expression.Call(
Expression.Constant(typeHandler, typeof(ITypeHandler)), Expression.Constant(typeHandler, typeof(ITypeHandler)),
typeof(ITypeHandler).GetMethod(nameof(typeHandler.Deserialize)), typeof(ITypeHandler).GetMethod(nameof(typeHandler.Deserialize)),