EF6中多个DbContext使用Code-First

因为有时候根据项目的不同,可能会需要多个库来保存数据。之前使用code-first都是根据单个数据库来生成,为此百度了一番之后,找到了这篇文章通过Migration在EF6中用多个DbContext

为此记录一下。

Enable-Migrations -ContextTypeName AbpFramewok.Infrastructure.EnterpriseDbContext -MigrationsDirectory:Migrations\Enterprise

ContextTypeNameDbContext的位置,即DbContext的命名空间加上DbContext的名称

MigrationsDirectory:需要迁移到的目标文件夹因为多个Dbcontext的迁移文件还是分开来放比较好、直观,另外的Dbcontext也是如此

Enable-Migrations -ContextTypeName AbpFramewok.Infrastructure.JobseekerDbContext -MigrationDirectory:Migrations\Jobseeker

添加迁移脚本,因为我们有多个Dbcontext,所以add-migration 需要指定Dbcontext的Configuration的位置

add-migration -ConfigurationTypeName AbpFramewok.Infrastructure.Migrations.Jobseeker.Configuration InitJobseekerDb
-ConfigurationTypeName 指定configuration的路径


同理 Update-database也需要指定Dbcontext
update-database -ConfigurationTypeName AbpFramewok.Infrastructure.Migrations.Jobseeker.Configuration 

 

 

转载于:https://www.cnblogs.com/louder/p/loudjay.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值