Skip to content

Instantly share code, notes, and snippets.

@sgoguen
Created July 1, 2011 17:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgoguen/1058974 to your computer and use it in GitHub Desktop.
Save sgoguen/1058974 to your computer and use it in GitHub Desktop.
EF CodeFirst - Generating a Database in F#
// This will generate a database, but EF will not materialize the objects
// because our types do not have default parameterless constructors
namespace DataModel
open System
open System.ComponentModel.DataAnnotations
open System.Data.Entity
type User = { mutable ID : int; mutable Name: string; mutable DB: DateTime; mutable Tasks: Task[];
mutable Projects: Project[] }
and Task = { mutable ID : int; mutable Short: string; mutable Due: DateTime; mutable Complete: bool }
and Project = { mutable ID : int; mutable Owner: User; mutable Tasks: Task[]; mutable Complete: bool }
type ProjectDB() =
inherit DbContext()
let mutable users : DbSet<User> = null
member public x.Users with get() = users //and set c = contacts <- c
module Projects =
let CreateDatabase() =
use db = new ProjectDB()
if db.Database.Exists() = true then
db.Database.Delete() |> ignore
let created = db.Database.Create()
true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment