Created
July 1, 2011 17:09
-
-
Save sgoguen/1058974 to your computer and use it in GitHub Desktop.
EF CodeFirst - Generating a Database in F#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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