Skip to content

Commit 85e1839

Browse files
committed
try get the mono build working
1 parent 73ea1fa commit 85e1839

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/SqlClient/ISqlCommand.fs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open System.Configuration
88
open System.Collections.Specialized
99

1010
open FSharp.Data.SqlClient
11+
open System.Linq
1112

1213
[<CompilerMessageAttribute("This API supports the FSharp.Data.SqlClient infrastructure and is not intended to be used directly from your code.", 101, IsHidden = true)>]
1314
type ISqlCommand =
@@ -185,10 +186,16 @@ type ``ISqlCommand Implementation``(cfg: DesignTimeConfig, connection: Connectio
185186
| _ ->
186187
match p.SqlDbType with
187188
| SqlDbType.Structured ->
189+
// TODO: Maybe make this lazy?
188190
//done via reflection because not implemented on Mono
189191
let sqlDataRecordType = typeof<SqlCommand>.Assembly.GetType("Microsoft.SqlServer.Server.SqlDataRecord", throwOnError = true)
190-
let records = typeof<Linq.Enumerable>.GetMethod("Cast").MakeGenericMethod(sqlDataRecordType).Invoke(null, [| value |]) :?> seq<Microsoft.SqlServer.Server.SqlDataRecord>
191-
p.Value <- if Seq.isEmpty records then null else records
192+
let records = typeof<Linq.Enumerable>.GetMethod("Cast").MakeGenericMethod(sqlDataRecordType).Invoke(null, [| value |])
193+
let hasAny = typeof<Linq.Enumerable>
194+
.GetMethods(BindingFlags.Static ||| BindingFlags.Public)
195+
.First(fun m -> m.Name = "Any" && m.GetParameters().Count() = 1)
196+
.MakeGenericMethod(sqlDataRecordType).Invoke(null, [| records |]) :?> bool
197+
198+
p.Value <- if not hasAny then null else records
192199
| _ -> p.Value <- value
193200

194201
elif p.Direction.HasFlag(ParameterDirection.Output) && value :? Array then

0 commit comments

Comments
 (0)