Zaid-Ajaj / LiteDB.FSharp

Advanced F# Support for LiteDB, an embedded NoSql database for .NET with type-safe query expression through F# quotations
MIT License
180 stars 22 forks source link

fluent mapping support #70

Open RicoSaupeBosch opened 1 year ago

RicoSaupeBosch commented 1 year ago

Hi

How do I use the fluent mapping support. I cannot seem to get it to work properly. I define the mapping below since the object dont have an ID property but that doesnt work when inserting the document to the database. I I used BSonmapper then the fluent mapping works but it doesnt support the fsharp types.

let createDatabaseUsing (store:Store) (config:AppSettings) =
        let mapper = FSharpBsonMapper()
        mapper.Entity<ServiceRequestAssignment>().Id(fun a -> a.RequestId) |> ignore
        mapper.Entity<SpSite>().Id(fun a -> a.SiteUrl) |> ignore

        let db =
            match store with
            | Store.InMemory -> 
                let memoryStream = new MemoryStream()
                new LiteDatabase(memoryStream, mapper)
            | Store.LocalDatabase -> 
                let dbFile = config.Database.File
                new LiteDatabase(dbFile, mapper)
        db

Exception

image

Could you suggest what I am doing wrong here?