Getting Started:
It's easy to get started with FSRepository 2.0.
1. Create a new F# Application (this example uses a project named TestFSRepository).
2. Follow the instructions defined in http://bloggemdano.blogspot.com/2011/01/fsrepository-new-nuget-package.html to install the FSRepository package.
3. Move the FSRepository.fs file above the Program.fs file (see http://lorgonblog.wordpress.com/2008/08/03/sneak-peeks-into-the-f-project-system-part-three/ for information on how to do this).
4. Add the following code to Program.fs and you're done.
open TestFSRepository.Repositories
type Program() =
static member Run() =
use sampleRepository = new SampleRepository()
let sample = new ASample()
sample.Id <- 1
sample.CreatedBy <- "Dan"
do sampleRepository.Add sample
do sampleRepository.Save()
sampleRepository.GetAll()
|> Seq.iter (fun (sample:ASample) ->
(printfn "Sample Id = %A" sample.Id |> ignore))
Program.Run()
Nice! But my preference for creating the object would be...
ReplyDeletelet sample = ASample(Id = 1, CreatedBy = "Dan")
Thanks Joel. Yes, that is nice and clean.
ReplyDeleteI would add that if those two parameters aren't optional they should be mandatory in the constructor. Surely EF provides a way to handle an entity like that?
ReplyDelete