实体框架$ C C首先迁移$:获得SQL脚本编程 [英] Entity Framework Code First Migrations: get sql scripts programmatically

查看:131
本文介绍了实体框架$ C C首先迁移$:获得SQL脚本编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在执行实体框架(V5)$ C $基于C语言的迁移为我的项目。

这是我们的客户的数据库管理员有时有点偏执,想用手来执行的SQL脚本。

既然我们已经得到了很多版本,我们支持的SqlServer和Oracle并行,我们不希望从所有可能的版本XXXX为YYYY管理若干更新脚本这难道不是可能获得编程SQL脚本以同样的方式,我把它的软件包管理器控制台

 更新,数据库-Script
 

因此​​,客户端将通过这取决于他的数据库系统,而目前的版本正确的SQL脚本输出一个简单的控制台应用程序中获取。

解决方案

 无功配置=新配置();
  VAR迁移=新DbMigrator(配置);

  VAR scriptor =新MigratorScriptingDecorator(迁移);
  VAR脚本= scriptor.ScriptUpdate(sourceMigration:空,targetMigration:零);
  Console.WriteLine(脚本);

  migrator.Update();

  变种未决= migrator.GetPendingMigrations();
 

详细信息: <一href="http://weblogs.asp.net/fredriknormen/archive/2012/02/15/using-entity-framework-4-3-database-migration-for-any-project.aspx">http://weblogs.asp.net/fredriknormen/archive/2012/02/15/using-entity-framework-4-3-database-migration-for-any-project.aspx


基本上你需要

  DbMigrator DB =新DbMigrator(这里的连接字符串);
db.Update(HERE目标版本);
 

I am implementing Entity Framework (v5) Code-Based Migrations for my project.

The db admins from our clients are sometimes a little bit paranoid and want to execute the sql scripts by hand.

Since we have got already many versions and we support SqlServer and Oracle parallel, we don't want to administer several update scripts from all possible versions x.x.x.x to y.y.y.y. Is it not possible to get programmatically the sql script in the same way as I call it in the Package Manager Console

Update-Database -Script

So the client would get via a simple console application depending his db system and current version the correct sql script as output.

解决方案

  var configuration = new Configuration();
  var migrator = new DbMigrator(configuration);

  var scriptor = new MigratorScriptingDecorator(migrator);
  var script = scriptor.ScriptUpdate(sourceMigration: null, targetMigration: null);
  Console.WriteLine(script);

  migrator.Update();

  var pending = migrator.GetPendingMigrations();

more info: http://weblogs.asp.net/fredriknormen/archive/2012/02/15/using-entity-framework-4-3-database-migration-for-any-project.aspx


basically you need

DbMigrator db = new DbMigrator(HERE CONNECTION STRING);
db.Update(HERE TARGET VERSION);

这篇关于实体框架$ C C首先迁移$:获得SQL脚本编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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