Entity Framework is the current data access technology baked into .net. It is dependant on Microsoft Sql Server but supports multiple versions and flavors. Migrations are code based and schema is defined using a fluent interface. It supports both targeted upgrading and downgrading. Migrations can be executed from the Package Manager Console or when an applicaiton starts. CLI execution is not supported.
- Maintained By: Microsoft
- NuGet
- Source
- Documentation
Install-Package EntityFramework
This is just a base class library, to interact with a database you must also install a package specific to that database.
Install-Package EntityFramework.SqlServer
EntityFramework.SqlServerCompact
namespace Migrations.EF.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class Init : DbMigration
{
public override void Up()
{
}
public override void Down()
{
}
}
}
All Entity Framework migration commands must be excuted from inside Visual Studio's Package Manager Console. This makes it difficult for CI systems to interact with the migrations to deploy them to an environment or generate data change scripts at build time.
Update-Database
Will connect to the database and apply any migrations that have not already been applied.
Update-Database -Verbose
Same as previous example but will print all sql statements to the console.
Add-Migration MeaningfullName
Will look at the current state of our model and generate migration for any changes from the previous migration.
Remove-Migration MeaningfullName
Will attempt to remove the migration from the project.
Update-Database -Script -SourceMigration: $InitialDatabase
Will generate an idempotent sql script containging all the migrations. This script can be run on an empty database or an existing database, only the missing migrations will be applied.
Update-Database -Script -TargetMigration $InitialDatabase
Will connect to the currently configured database and generate destructive scripts to drop all migrations applied back to an empty database.