Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
657 views
in Technique[技术] by (71.8m points)

xamarin - Enable Entity Framework migrations in Mono

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

Update for EF 6.3 ??

A command named ef6.exe has been added to the NuGet package. It contains corresponding commands for each of the PMC commands:

|        PMC        |        ef6.exe        |
| ----------------- | --------------------- |
| Enable-Migrations | ef6 migrations enable |
| Add-Migration     | ef6 migrations add    |
| Update-Database   | ef6 database update   |
| Get-Migrations    | ef6 migrations list   |

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...