Skip to content

Commit 2d7893b

Browse files
Vasily KirichenkoVasily Kirichenko
authored andcommitted
pass null if table value argument has zero records
1 parent e818907 commit 2d7893b

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/SqlClient/ISqlCommand.fs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,26 +173,22 @@ type ``ISqlCommand Implementation``(cfg: DesignTimeConfig, connection: Connectio
173173

174174
static member internal SetParameters(cmd: SqlCommand, parameters: (string * obj)[]) =
175175
for name, value in parameters do
176-
177176
let p = cmd.Parameters.[name]
178177

179178
if p.Direction.HasFlag(ParameterDirection.Input)
180179
then
181-
if value = null
182-
then
180+
if isNull value then
183181
p.Value <- DBNull.Value
184182
else
185-
if not( p.SqlDbType = SqlDbType.Structured)
186-
then
187-
p.Value <- value
188-
else
189-
//p.Value <- value |> unbox |> Seq.cast<Microsoft.SqlServer.Server.SqlDataRecord>
190-
191-
//done via reflection because not implemented on Mono
192-
let sqlDataRecordType = typeof<SqlCommand>.Assembly.GetType("Microsoft.SqlServer.Server.SqlDataRecord", throwOnError = true)
193-
p.Value <- typeof<Linq.Enumerable>.GetMethod("Cast").MakeGenericMethod(sqlDataRecordType).Invoke(null, [| value |])
194-
elif p.Direction.HasFlag(ParameterDirection.Output) && value :? Array
195-
then
183+
match p.SqlDbType with
184+
| SqlDbType.Structured ->
185+
p.Value <-
186+
match value |> unbox |> Seq.cast<Microsoft.SqlServer.Server.SqlDataRecord> with
187+
| records when Seq.isEmpty records -> null
188+
| records -> records
189+
| _ -> p.Value <- value
190+
191+
elif p.Direction.HasFlag(ParameterDirection.Output) && value :? Array then
196192
p.Size <- (value :?> Array).Length
197193

198194
//Execute/AsyncExecute versions

0 commit comments

Comments
 (0)