实体框架$ C C首先迁移$:获得SQL脚本编程脚本、实体、框架、SQL

2023-09-03 07:54:12 作者:浅巷墨漓~

我在执行实体框架(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();
 
Ms SQL 数据库脚本生成

详细信息: 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);

 
精彩推荐
图片推荐