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

求教多库的使用方法! #52

Open
AS-D opened this issue Dec 2, 2020 · 9 comments
Open

求教多库的使用方法! #52

AS-D opened this issue Dec 2, 2020 · 9 comments

Comments

@AS-D
Copy link

AS-D commented Dec 2, 2020

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

@VictorTzeng
Copy link
Owner

VictorTzeng commented Dec 2, 2020

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

@AS-D
Copy link
Author

AS-D commented Dec 3, 2020

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

@VictorTzeng
Copy link
Owner

VictorTzeng commented Dec 3, 2020

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

@AS-D
Copy link
Author

AS-D commented Dec 3, 2020

Uploading image.png…

@VictorTzeng
Copy link
Owner

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

@AS-D
Copy link
Author

AS-D commented Dec 14, 2020

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

@VictorTzeng
Copy link
Owner

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

@AS-D
Copy link
Author

AS-D commented Dec 16, 2020

奥奥,好的

@AS-D
Copy link
Author

AS-D commented Dec 21, 2020

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

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

2 participants