fsprojects / FSharp.Data.SqlClient

A set of F# Type Providers for statically typed access to MS SQL database
http://fsprojects.github.io/FSharp.Data.SqlClient/
Other
204 stars 71 forks source link

TVP Column Ordering is incorrect as of version 2.1.0 #420

Closed suou-ryuu closed 2 years ago

suou-ryuu commented 2 years ago

Issue Summary

When using a TVP, containing multiple columns, the columns order in F# is not the expected order (the order the columns were declared, i.e. column_id).

To Reproduce

CREATE TYPE [dbo].[TVPColumnOrder] AS TABLE(
    [Param1] INT NOT NULL,
    [Param2] NVARCHAR(100) NOT NULL,
    [Param3] BIT NOT NULL
)
GO

CREATE PROCEDURE [dbo].[TestTVPColumnOrder](
    @tvpColumnOrder [dbo].[TVPColumnOrder] READONLY
)
AS
    SELECT *
    FROM   @tvpColumnOrder
GO
type TestTVPColumnOrder = SqlCommandProvider<"EXEC [dbo].[TestTVPColumnOrder] @tvp", ConnectionStrings.AdventureWorksLiteral>

let someFunc () =
    use cmd = new TestTVPColumnOrder(ConnectionStrings.AdventureWorksLiteral)

    [
        (1, "some string",        true)
        (2, "some other string",  false)
        (3, "yet another string", true)
    ]
    |> Seq.map (fun (i, s, b) -> TestTVPColumnOrder.TVPColumnOrder(i, s, b))
...

Error

The above will result in 2 compilation errors:

The type required for this expression is 'bool', but 'string' was specified

and

The type required for this expression is 'string', but 'bool' was specified

Referring to the 2nd and 3rd arguments to TestTVPColumnOrder.TVPColumnOrder

Expected behavior

Things to compile without error.

What you can do