visual-studio - 如何从自定义 NuGet 包运行 EF 迁移?
问题描述
我有 ac# 类库,它有自己的数据库上下文和实体框架迁移。
我的解决方案包含一个将类库作为项目参考引用的网站。
通过将默认项目设置为我的类库并使用以下命令,我可以从包管理器控制台为 Visual Studio 中的类库应用 EF 迁移:
update-database -StartupProject MyMainWebProj -Context MyClassLibDbContext
我为类库创建了一个私有 NuGet 包,并更新了网站以引用 NuGet 包而不是项目引用。
现在我无法弄清楚如何运行 EF 迁移,因为类库是通过 NuGet 包引用的。
解决方案
您可以在服务配置期间使用 Use*() 方法的构建器对象,如下所述:https ://github.com/jasontaylordev/CleanArchitecture/blob/d0f133ee026aec5cd5856c5592c307b5f20fa8e4/src/Infrastructure/DependencyInjection.cs#L28
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
configuration.GetConnectionString("DefaultConnection"),
b => b.MigrationsAssembly(typeof(SomeClassInTheOtherAssembly).Assembly.FullName)));
推荐阅读
- python - 不允许主机连接到此 MySQL 服务器(来自 VM)
- asp.net-core - 在 asp.net 核心控制器中,HTTP 上下文为空
- c# - 如何在 VirtoCommerce 中发送通知
- javascript - Javascript | 'element.style.display' 状态检查在'if gate' 中不起作用?
- c++ - 在 boost::spirit::x3 中合成 std::pair 属性
- excel - VBA 将行数复制到新工作簿
- mysql - 与 CONCAT 一起使用时,SQL 命令在查询中挂起
- visual-studio - Visual Studio 2019 - 代码图:禁用源类/dotnet 核心的“直接”引用
- php - PHP数组:如何使用不同的值进行查询
- sql - 从 SQL 到 Laravel 查询构建器