1. 程式人生 > >dotnetcore ef 呼叫多個數據庫時使用者命令執行操作報錯

dotnetcore ef 呼叫多個數據庫時使用者命令執行操作報錯

dotnetcore ef 呼叫多個數據庫時使用者命令執行操作報錯

1、多個DbContext 時報錯:

報錯:

More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.

解決辦法:

dotnet ef migrations add initail -c PermissionDbContext

成功之後

dotnet ef database update -c PermissionDbContext

2、如果 DbContext 在另一個 DLL 中時報錯:

解決辦法:

services.AddDbContext<PermissionDbContext>(options =>
options.UseSqlServer(configuration.GetConnectionString("PermissionConnection"), b => b.MigrationsAssembly(assemblyName)));

其中 assemblyName 是主DLL 名稱的字串常量。(不知道為什麼,它不能為變數 AppDomain.CurrentDomain.FriendlyName)。