VictorTzeng / Zxw.Framework.NetCore

基于EF Core的Code First模式的DotNetCore快速开发框架,其中包括DBContext、IOC组件autofac和AspectCore.Injector、代码生成器(也支持DB First)、基于AspectCore的memcache和Redis缓存组件,以及基于ICanPay的支付库和一些日常用的方法和扩展,比如批量插入、更新、删除以及触发器支持,当然还有demo。欢迎提交各种建议、意见和pr~

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

求教多库的使用方法!

AS-D opened this issue · comments

commented

求教详细的多库使用方法,不知道为何我使用多库时
老是报错

commented

请贴一下代码和错误信息,谢谢 @AS-D

commented

Startup 文件

services.Configure(options =>
{
options.TagName = "db0";
options.ConnectionString =
"Data Source=F:\EF6.db;Version=3;";
//options.ModelAssemblyName = "Zxw.Framework.Website.Models";
});

        services.AddDbContextFactory(factory =>
        {
            factory.AddDbContext<SQLiteDbContext>(new DbContextOption()
            {
                TagName = "db1",
                ConnectionString = "Data Source=F:\\EF6.db;Version=3;"
            });
            factory.AddDbContext<SqlServerDbContext>(new DbContextOption()
            {
                TagName = "db3",
                ConnectionString = "data source=serverb;initial catalog=NetCoreDemo;persist security info=True;user id=sa;password=sa.123;multipleactiveresultsets=True;application name=EntityFramework",
            });
            factory.AddDbContext<SqlServerDbContext>(new DbContextOption()
            {
                TagName = "db2",
                ConnectionString = "data source=serverb;initial catalog=TestDb1;persist security info=True;user id=sa;password=sa.123;multipleactiveresultsets=True;application name=EntityFramework",
            });
        });

        services.AddScoped<IDbContextCore, SQLiteDbContext>(); //注入EF上下文

进入SQLiteDbContext实例化时连接不对
image

commented

贴一下你获取DBContext的代码段,这里明显TagName没对应上
image

commented

Uploading image.png…

commented

image
看不到图片,周末在家再测试一下

commented

代码我上传到github了,麻烦您有时间帮忙看一下。谢谢https://github.com/AS-D/Zxw-

commented

暂不支持同时注入多个同类型的数据库链接,这个功能后续会加上

commented

奥奥,好的

commented

image
大佬,我加了2个集合临时解决了这个问题,不过感觉有限制,不知道您是否有更好的解决方法