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)。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM