如何在EntityFramework Codefirst中以编程方式更新数据库? [英] How to update-database Programmatically in EntityFramework Codefirst?

查看:265
本文介绍了如何在EntityFramework Codefirst中以编程方式更新数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在ASP.NET MVC框架(大学最终项目)中写一个简单的 CMS 。我的问题是模块的数据迁移策略,每个模块将更新在安装数据库模式时,必须在模块安装system.ok中实现数据库迁移机制,实体框架中的数据迁移已经存在(感谢MS)但是迁移命令在包管理器控制台中运行。有没有办法以编程方式运行数据迁移代码?
任何帮助都是非常感激的。

解决方案

此类暴露了代码中的EF迁移:



System.Data .Entity.MigrateDatabaseToLatestVersion



在EF中,迁移在整个数据库上运行,但不是一个模块化的部分。






只是发现这个类:



System.Data.Entity.Migrations.DbMigrator


i am writing a simple CMS over ASP.NET MVC framework (for college final project).my problem is with module's data-migration strategy.as each module will update the database schema when it is installed , a database migration mechanism must be implemented in module installation system.ok , data-migration in entity framework is already there (thanks to MS) , but the migration commands run in package manager console.is there any way to run a Data-Migration code Programmatically? any help is very appreciated.

解决方案

This class exposes the EF migrations in code:

System.Data.Entity.MigrateDatabaseToLatestVersion

In EF, migrations work on a whole database though - not modular parts of one.


Just found this class too:

System.Data.Entity.Migrations.DbMigrator

这篇关于如何在EntityFramework Codefirst中以编程方式更新数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆