weird behavior using f# class with redis service stack lib

Go To


I'm testing a bit redis using .Net, I've read this tutorial and follow using c# and worked perfect, now when I'm trying translate this to f# I've a weird behavior, first I create a simple f# class (using type didn't work neither but it was expected)...basicaly the class is something like this:

//I ve used [<Class>] to
type Video (id : int, title : string , image : string , url : string) =
  member this.Id = id
  member this.Title = title
  member this.Image = image
  member this.Url = url

when I run the code, my db save an empty data, if I use a c# class inside my f# code this work, so I'm sure than the problem is the f# class...How can resolve this without depend c# code inside my f# code

Thanks !!!

2012-04-04 04:00
by clagccs
you may start by showing us the code that fails! (DB access) - I guess your DRM want's it's types to be either mutable, having an constructor without parameters or some special attribute - Carsten 2012-04-04 04:17
I'm guessing mutable types too. I ran into a very similar issue when I was trying to interface some F# code to RavenDB - Onorio Catenacci 2012-04-04 12:57


Based on your tutorial, it looks like you want your F# Video class to be full of getter and setter properties instead of having a constructor with getters only as it is now (and it is a class, which you can verify by running it through FSI).

You can achieve this using a record type full of mutable fields (which is compiled down to a class type full of public getters and setters):

type Video = { 
    mutable Id : int
    mutable Title : string
    mutable Image : byte[]
    mutable Url : string
2012-04-04 04:15
by Stephen Swensen