在Mono中启用实体框架迁移 [英] Enable Entity Framework migrations in Mono
问题描述
我已经在Mac OS上使用Xamarin Studio开始构建一个ASP.NET MVC3项目。我现在想为项目添加新的属性和模型,但是在我的生活中,我无法了解如何运行Nuget软件包管理器控制台,以便运行Enable-Migrations命令。
我要求太多了吗?这是可能的还是我必须回到Windows上的Visual Studio?
所有的实体框架迁移命令只是在底层API上的薄包装。要启用迁移,只需在项目中创建一个派生自 DbMigrationsConfiguration< TContext>
的新类。
code> Add-Migration 使用类似于以下的代码。
var config = new MyMigrationsConfiguration();
var scaffolder = new MigrationScaffolder(config);
var migration = scaffolder.Scaffold(Migration1);
File.WriteAllText(migration.MigrationId +.cs,migration.UserCode);
File.WriteAllText(migration.MigrationId +.Designer.cs,migration.DesignerCode);
使用(var writer = new ResXResourceWriter(migration.MigrationId +.resx))
{
foreach(var resource in migration.Resources)
{
writer.AddResource(resource.Key,resource.Value);
}
}
对于更新数据库
请参阅 Running& Rowan Miller编写的代码迁移脚本。
I've started building an ASP.NET MVC3 project on Mac OS using Xamarin Studio. I now want to add new properties and models to the project but I can't for the life of me work out how to run the Nuget Package Manager console in order to run the Enable-Migrations command.
Am I asking too much? Is this possible or will I have to go back to Visual Studio on Windows?
All of the Entity Framework Migrations commands are just thin wrappers over an underlying API. To enable migrations, simply create a new class that derives from DbMigrationsConfiguration<TContext>
in your project.
For Add-Migration
use code similar to the following.
var config = new MyMigrationsConfiguration();
var scaffolder = new MigrationScaffolder(config);
var migration = scaffolder.Scaffold("Migration1");
File.WriteAllText(migration.MigrationId + ".cs", migration.UserCode);
File.WriteAllText(migration.MigrationId + ".Designer.cs", migration.DesignerCode);
using (var writer = new ResXResourceWriter(migration.MigrationId + ".resx"))
{
foreach (var resource in migration.Resources)
{
writer.AddResource(resource.Key, resource.Value);
}
}
For Update-Database
see Running & Scripting Migrations from Code by Rowan Miller.
这篇关于在Mono中启用实体框架迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!