Skip to content

Instantly share code, notes, and snippets.

@odytrice
Last active October 14, 2016 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odytrice/a09d6fc0d81fd2aa52eedcbabac01151 to your computer and use it in GitHub Desktop.
Save odytrice/a09d6fc0d81fd2aa52eedcbabac01151 to your computer and use it in GitHub Desktop.
Sample EF Core Migration
namespace MyAPI.Migrations
open System
open System.Collections.Generic
open Microsoft.EntityFrameworkCore
open Microsoft.EntityFrameworkCore.Migrations
open Microsoft.EntityFrameworkCore.Metadata
open Microsoft.EntityFrameworkCore.Infrastructure
open Microsoft.EntityFrameworkCore.Migrations.Operations
open Microsoft.EntityFrameworkCore.Migrations.Operations.Builders
//Table Types
type WeatherEventsTable =
{ Id : OperationBuilder<AddColumnOperation>
Date: OperationBuilder<AddColumnOperation>
MostCommonWord: OperationBuilder<AddColumnOperation>
Time: OperationBuilder<AddColumnOperation>
Type: OperationBuilder<AddColumnOperation> }
[<DbContext(typeof<WeatherContext>)>]
[<Migration("20161006200628_Init")>]
type Init() =
inherit Migration()
override this.Up(migrationBuilder: MigrationBuilder) =
migrationBuilder.CreateTable(
name = "WeatherEvents",
columns =
(fun table ->
{ Id = table.Column<int>(nullable = false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn)
Date = table.Column<DateTime>(nullable = false)
MostCommonWord = table.Column<string>(nullable = true)
Time = table.Column<TimeSpan>(nullable = false)
Type = table.Column<int>(nullable = false) }),
constraints =
fun table ->
table.PrimaryKey("PK_WeatherEvents", (fun x -> x.Id :> obj))|> ignore ) |> ignore
override this.Down(migrationBuilder: MigrationBuilder) =
migrationBuilder.DropTable(name = "WeatherEvents") |> ignore
override this.BuildTargetModel(modelBuilder: ModelBuilder) =
modelBuilder
.HasAnnotation("ProductVersion", "1.0.1")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn)
|> ignore
modelBuilder.Entity("MyAPI.Domain.WeatherEvent",
fun b ->
b.Property<int>("Id").ValueGeneratedOnAdd() |> ignore
b.Property<DateTime>("Date") |> ignore
b.Property<string>("MostCommonWord") |> ignore
b.Property<TimeSpan>("Time") |> ignore
b.Property<int>("Type") |> ignore
b.HasKey("Id") |> ignore
b.ToTable("WeatherEvents") |> ignore)|> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment