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

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

问题描述

我正在 ASP.NET MVC 框架上编写一个简单的 CMS(用于大学期末项目).我的问题是模块的数据迁移策略.因为每个模块都会在更新数据库架构时安装,必须在模块安装system.ok中实现数据库迁移机制,实体框架中的data-migration已经存在(感谢MS),但迁移命令在包管理器控制台中运行.在那里以编程方式运行 Data-Migration 代码的任何方式?非常感谢任何帮助.

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.

推荐答案

此类在代码中公开 EF 迁移:

This class exposes the EF migrations in code:

System.Data.Entity.MigrateDatabaseToLatestVersion

在 EF 中,迁移适用于整个数据库 - 而不是一个的模块化部分.

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

也发现了这个类:

系统.Data.Entity.Migrations.DbMigrator

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

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