Search code examples
f#ormlite-servicestack

ServiceStack.OrmLite Autoincrement not working with F#


I am using OrmLite with F# on Mono.

I have the following basic structure:

type NestedTree() =
    static member val table_name = String.Empty with get, set
    //DB fields
    [<AutoIncrement>]
    [<PrimaryKey>]
    member val id = 0 with get, set
    member val parent_id = Nullable<_>(null) with get, set
    member val name = String.Empty with get, set
    member val lft = 0 with get, set
    member val rgt = 0 with get, set
    member val depth = 0 with get, set

However, the Autoncrement property is not taken into account when I use :

    use conn = dbFactory.Open()
    let item = ...
    conn.Insert(item)

I assume this is because of the default value in F# set at 0.

Am I wrong ? If not, is there a way to circumvent it ?

Many thanks for your help !


Solution

  • It seems it is due to these attributes not being declared as inherited, and I was using them with a subclass of NestedTree, hence the issue.

    See http://msdn.microsoft.com/en-us/library/tw5zxet9.aspx :

    [System.AttributeUsage(System.AttributeTargets.All, AllowMultiple = false, Inherited = true)]
    

    It would be nice to mark OrmLite attributes as inheritable so that we can inherit rather than override.