diff --git a/src/DbTests/DbTests.fsproj b/src/DbTests/DbTests.fsproj
index 43e9953..7e572e4 100644
--- a/src/DbTests/DbTests.fsproj
+++ b/src/DbTests/DbTests.fsproj
@@ -58,6 +58,7 @@
+
diff --git a/src/DbTests/ExecuteTests.fs b/src/DbTests/ExecuteTests.fs
index 4233b5d..283f65b 100644
--- a/src/DbTests/ExecuteTests.fs
+++ b/src/DbTests/ExecuteTests.fs
@@ -2807,6 +2807,19 @@ let execTests =
)
]
+ testList (nameof DbGen.Scripts.ManyColumns) [
+ yield!
+ allExecuteMethodsAsSingle
+ |> List.map (fun (name, exec) ->
+ testCase name <| fun () ->
+ let res =
+ DbGen.Scripts.ManyColumns
+ .WithConnection(Config.connStr)
+ |> exec
+ test <@ res.Value.Column1 = None @>
+ test <@ res.Value.Column600 = None @>
+ )
+ ]
testList (nameof DbGen.Scripts.NormalParams) [
yield!
diff --git a/src/DbTests/SQL/ManyColumns.sql b/src/DbTests/SQL/ManyColumns.sql
new file mode 100644
index 0000000..55d57bc
--- /dev/null
+++ b/src/DbTests/SQL/ManyColumns.sql
@@ -0,0 +1,12 @@
+DECLARE @numCols INT = 600
+DECLARE @sql NVARCHAR(MAX) = 'SELECT '
+
+DECLARE @colNo INT = 1
+
+WHILE (@colNo <= @numCols)
+BEGIN
+ SET @sql += 'Column' + CAST(@colNo AS NVARCHAR) + ' = NULL' + CASE @colNo WHEN @numCols THEN '' ELSE ', ' END
+ SET @colNo += 1
+END
+
+EXEC sp_executesql @sql
diff --git a/src/Facil.Generator/Render.fs b/src/Facil.Generator/Render.fs
index a05a671..1e70bc0 100644
--- a/src/Facil.Generator/Render.fs
+++ b/src/Facil.Generator/Render.fs
@@ -301,14 +301,19 @@ let private renderProcOrScript (cfg: RuleSet) (tableDtos: TableDto list) (execut
""
$"let getItem (reader: SqlDataReader){getItemReturnTypeExpr} ="
+ yield! indent [
+ for c in cols do
+ if c.IsNullable then
+ $"let ``{c.Name.Value}`` = if reader.IsDBNull ``ordinal_{c.Name.Value}`` then {outOptionNone} else reader.{c.TypeInfo.SqlDataReaderGetMethodName} ``ordinal_{c.Name.Value}`` |> {outOptionSome}"
+ else
+ $"let ``{c.Name.Value}`` = reader.{c.TypeInfo.SqlDataReaderGetMethodName} ``ordinal_{c.Name.Value}``"
+ ]
+
yield! indent [
getItemRecordStart
yield! indent [
for c in cols do
- if c.IsNullable then
- $"``{getColName c}`` = if reader.IsDBNull ``ordinal_{c.Name.Value}`` then {outOptionNone} else reader.{c.TypeInfo.SqlDataReaderGetMethodName} ``ordinal_{c.Name.Value}`` |> {outOptionSome}"
- else
- $"``{getColName c}`` = reader.{c.TypeInfo.SqlDataReaderGetMethodName} ``ordinal_{c.Name.Value}``"
+ $"``{getColName c}`` = ``{c.Name.Value}``"
]
getItemRecordEnd
]
@@ -484,14 +489,19 @@ let private renderProcOrScript (cfg: RuleSet) (tableDtos: TableDto list) (execut
""
$"let getItem (reader: SqlDataReader){getItemReturnTypeExpr} ="
+ yield! indent [
+ for c in cols do
+ if c.IsNullable then
+ $"let ``{c.Name.Value}`` = if reader.IsDBNull ``ordinal_{c.Name.Value}`` then {outOptionNone} else reader.{c.TypeInfo.SqlDataReaderGetMethodName} ``ordinal_{c.Name.Value}`` |> {outOptionSome}"
+ else
+ $"let ``{c.Name.Value}`` = reader.{c.TypeInfo.SqlDataReaderGetMethodName} ``ordinal_{c.Name.Value}``"
+ ]
+
yield! indent [
getItemRecordStart
yield! indent [
for c in cols do
- if c.IsNullable then
- $"``{getColName c}`` = if reader.IsDBNull ``ordinal_{c.Name.Value}`` then {outOptionNone} else reader.{c.TypeInfo.SqlDataReaderGetMethodName} ``ordinal_{c.Name.Value}`` |> {outOptionSome}"
- else
- $"``{getColName c}`` = reader.{c.TypeInfo.SqlDataReaderGetMethodName} ``ordinal_{c.Name.Value}``"
+ $"``{getColName c}`` = ``{c.Name.Value}``"
]
getItemRecordEnd
]