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

Nullable DateTime throwing exception #66

Open Blener opened 3 years ago

Blener commented 3 years ago

Hi @Zaid-Ajaj Nullable DateTime is throwing when trying to read from the database. When inserting the value in the database, the JToken used is StartObject, but when reading it expects DateTime, that throws an exception.

image

These are the test cases:

testCase "Documents with Nullable DateTime != null can be used" <| fun _ ->
            useDatabase mapper<| fun db ->
                let docs = db.GetCollection<RecNullableDateTime>()
                let date = Nullable DateTime.MinValue
                docs.Insert ({ Id = 1; Date = date }) |> ignore
                docs.FindAll()
                |> Seq.tryHead
                |> function
                    | None -> fail()
                    | Some doc ->
                        match doc.Id, doc.Date with
                        | 1, date -> pass()
                        | _ -> fail()

        testCase "Documents with Nullable DateTime = null can be used" <| fun _ ->
            useDatabase mapper<| fun db ->
                let docs = db.GetCollection<RecNullableDateTime>()
                let date = Nullable()
                docs.Insert ({ Id = 1; Date = date }) |> ignore
                docs.FindAll()
                |> Seq.tryHead
                |> function
                    | None -> fail()
                    | Some doc ->
                        match doc.Id, doc.Date with
                        | 1, date -> pass()
                        | _ -> fail()