Skip to content

Commit cef7194

Browse files
Fix: non primitive out types
1 parent 5cd650a commit cef7194

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ local.properties
4646
*.suo
4747
*.user
4848
*.sln.docstates
49-
49+
launchSettings.json
5050
# Build results
5151

5252
[Dd]ebug/

src/SqlClient.DesignTime/DesignTime.fs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ type DesignTime private() =
7878

7979
if t.IsArray
8080
then Expr.Value(Array.CreateInstance(t.GetElementType(), param.Size))
81-
else Expr.Value(Activator.CreateInstance(t), t)
81+
elif t.IsPrimitive then
82+
Expr.Value(Activator.CreateInstance(t), t)
83+
else
84+
Expr.DefaultValue(t)
8285

8386
<@@ (%%Expr.Value(param.Name) : string), %%Expr.Coerce(value, typeof<obj>) @@>
8487
)
@@ -100,9 +103,10 @@ type DesignTime private() =
100103
if sqlParam.Direction.HasFlag( ParameterDirection.Output)
101104
then
102105
let mi =
103-
typeof<Mapper>
104-
.GetMethod("SetRef")
105-
.MakeGenericMethod( sqlParam.TypeInfo.ClrType)
106+
ProvidedTypeBuilder.MakeGenericMethod(
107+
typeof<Mapper>
108+
.GetMethod("SetRef"),
109+
[sqlParam.TypeInfo.ClrType])
106110
Expr.Call(mi, [ argExpr; Expr.Var arr; Expr.Value index ]) |> Some
107111
else
108112
None

src/SqlClient/Shared.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ type Mapper private() =
3535
mapper values
3636

3737
static member SetRef<'t>(r : byref<'t>, arr: (string * obj)[], i) =
38-
r <- arr.[i] |> snd |> unbox
38+
let value = arr.[i] |> snd
39+
r <-
40+
match value with
41+
| :? 't as v -> v
42+
| _ (* dbnull *) -> Unchecked.defaultof<'t>
3943

4044
type Column = {
4145
Name: string

0 commit comments

Comments
 (0)