Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为不同实例提供不同的表结构缓存 #1835

Closed
ZF-Follower opened this issue Jun 25, 2024 · 1 comment
Closed

为不同实例提供不同的表结构缓存 #1835

ZF-Follower opened this issue Jun 25, 2024 · 1 comment

Comments

@ZF-Follower
Copy link

ZF-Follower commented Jun 25, 2024

Feature 特性

// c#     new FreeSqlBuilder().UseCustomTableEntityCacheFactory(() =>
                            {
                                
                                Tkey _dbkey = (Tkey)AccessHelper.ReadPrivateField(fsq, "_dbkey");
                                Trace.WriteLine($"切换使用dbkey:{_dbkey}");
                                var cache = FsqExtensionsCache<Tkey>.EntityConfigCache.GetOrAdd(_dbkey, (key) => new());
                                return cache;
                            });

简要描述原因

// c#  FreeSqlCloud中我使用同类型的数据库 PostgreSQL, 但是我的租户在不同searchpath下面,我使用了ConfigEntity增加和xxx.tbname.当我切换或者use时 我看FreeSql.Internal.Utils.ChacheTableEntityFactory  是一个全局静态的字段,返回的映射是最后一次注册的func。我需要根据当前使用的dbk返回对应的ChacheTableEntityFactory 方法。能加一个当前freesql实例参数当做标识,或者把ChacheTableEntityFactory  绑定到freesql实例上面

使用场景

    new FreeSqlBuilder().UseCustomTableEntityCacheFactory((freesql) =>
                            {
                                
                                Tkey _dbkey = (Tkey)AccessHelper.ReadPrivateField(freesql, "_dbkey");
                                Trace.WriteLine($"切换使用dbkey:{_dbkey}");
                                var cache = FsqExtensionsCache<Tkey>.EntityConfigCache.GetOrAdd(_dbkey, (key) => new());
                                return cache;
                            });
@ZF-Follower
Copy link
Author

改为

new FreeSqlBuilder().UseConnectionFactory(DataType.CustomPostgreSQL, () => new Npgsql.NpgsqlConnection(tenant_connectionString), typeof(FreeSql.PostgreSQL.PostgreSQLProvider<>))

这种方式不用管UseCustomTableEntityCacheFactory,直接支持searchpath

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant