Call of dr.IsDBNull throws InvalidCastException.
MCVE
Replace printUser function from the Sample with one below:
let printUser (dr: IDataRecord) =
let id = (dr?id).Value
let name = (dr?name).Value
let address =
let ai = dr.GetOrdinal("address")
if dr.IsDBNull ai then None
else dr.GetString(ai) |> Some
|> function
| None -> "No registered address"
| Some x -> x
printfn "Id: %d; Name: %s; Address: %s" id name address
Unhandled exception. System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.DBNull'.
at Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicFunctions.UnboxGeneric[T](Object source) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\prim-types.fs:line 598
at FsSqlImpl.DictDataRecord.System-Data-IDataRecord-IsDBNull(Int32 i)
Call of
dr.IsDBNullthrows InvalidCastException.MCVE
Replace
printUserfunction from the Sample with one below: