Coldairarrow / EFCore.Sharding

Database Sharding For EFCore
Apache License 2.0
694 stars 143 forks source link

是否可以考虑将类保护属性设置为公开 #77

Open yangxuilyx opened 3 years ago

yangxuilyx commented 3 years ago

你好!我想重写下IDbFactory,但是源码中所有的类都是internal的,外部无法调用,是否可以考虑将类设置为public,这样上层调用可以更加个性化的重写或者派生,很多自定义需求能更好的解决呢。谢谢!

Coldairarrow commented 3 years ago

什么场景需要?

yangxuilyx commented 3 years ago

项目中引用的dll中有[Table()]的类是protected的,注入IShardingDbAccessor时会因为protected类型获取失败。 所以我想重写IDbFactory 返回继承至GenerateDbContext的自定义Context,自己处理Entity的注入

yangxuilyx commented 3 years ago

或者麻烦你说一下怎么设置GenerateDbContext的Paramter属性,我看到源码中有这个,但是没找到怎么调用

Coldairarrow commented 3 years ago

项目中引用的dll中有[Table()]的类是protected的 这个改为公开会怎样

Coldairarrow commented 3 years ago

你这个情况拿到GenerateDbContext也没用,Entity是自动扫描的

yangxuilyx commented 3 years ago

是嘛,我看你的源代码中是有Paramter属性的,如果拿到的话我就可以通过设置Paramter的EntityTypes这个属性,从而不使用自动扫描了

yangxuilyx commented 3 years ago

项目中引用的dll中有[Table()]的类是protected的 是引用的第三方库,改不了这个源码

Coldairarrow commented 3 years ago

public IDbAccessor GetDbAccessor(string conString, DatabaseType dbType, string entityNamespace = null, string suffix = null) 你可以指定命名空间啊 命名空间总不一样吧?

    IShardingBuilder UseDatabase(string conString, DatabaseType dbType, string entityNamespace = null);
yangxuilyx commented 3 years ago

这样使用还是一样的会扫描全局。 注释掉AddDataSource会报错 ` services.AddEFCoreSharding(config => { //添加数据源 config.AddDataSource(_appConfiguration.GetConnectionString("Default"), ReadWriteType.Read | ReadWriteType.Write, DatabaseType.SqlServer);

            config.SetDateSharding<Student>(nameof(Student.CreationTime), ExpandByDateMode.PerHour,
                DateTime.Now.AddDays(-1));

            config.UseDatabase(_appConfiguration.GetConnectionString("Default"),
                DatabaseType.SqlServer, "Sharding.Test.Students");
        });

`

yangxuilyx commented 3 years ago

按照示例我把顺序修改为下面这样子,也不行。 ` services.AddEFCoreSharding(config => {

            config.UseDatabase(_appConfiguration.GetConnectionString("Default"),
                DatabaseType.SqlServer, "Sharding.Test");

            config.AddDataSource(_appConfiguration.GetConnectionString("Default"), ReadWriteType.Read | ReadWriteType.Write, DatabaseType.SqlServer);

            config.SetDateSharding<Student>(nameof(Student.CreationTime), ExpandByDateMode.PerHour,
                DateTime.Now.AddDays(-1));

        });

`

yangxuilyx commented 3 years ago

我看示例中是有这个SetEntityAssembly用法的,5.0.x版本没有了吗? ` services.AddEFCoreSharding(config => { config.SetEntityAssembly("EFCore.Sharding");

            //SQLITE1作为主库(写库)
            //SQLITE2作为从库(读库)
            config.UseDatabase(new (string, ReadWriteType)[]
            {
                (Config.SQLITE1, ReadWriteType.Write),
                (Config.SQLITE2, ReadWriteType.Read)
            }, DatabaseType.SQLite);
        });

`

yangxuilyx commented 3 years ago

public IDbAccessor GetDbAccessor(string conString, DatabaseType dbType, string entityNamespace = null, string suffix = null) 你可以指定命名空间啊 命名空间总不一样吧?

    IShardingBuilder UseDatabase(string conString, DatabaseType dbType, string entityNamespace = null);

请问能给个具体的用法吗?谢谢

yangxuilyx commented 3 years ago

我把项目上传到GitHub了,麻烦你方便的话帮我看一下哪里不对,谢谢! https://github.com/yanusosu/Sharding.Test

Coldairarrow commented 3 years ago

给一个干净的demo

yangxuilyx commented 3 years ago

已新建demo,fork自这个项目,测试项目是:Demo.DateSharding,麻烦你了,谢谢! https://github.com/yanusosu/EFCore.Sharding