Closed TheJayMann closed 2 months ago
I believe I have an idea as to why this is happening.
First, looking at .NET source, https://source.dot.net/#System.Data.Common/System/Data/ParameterDirection.cs, the values for Input
, Output
, InputOutput
, and Return
value are 1, 2, 3, and 6. In the serialized schema definition created by MSSQL provider, the direction is 6, or ReturnValue
. In the getSprocReturnColumns
function, if a connection is present, a list of return columns are generated from the provider, and added to the schema cache, and returned. However, without a connection, the list of columns saved to the schema cache is filtered based on the direction being Input
. As the return values are given a direction of ReturnValue
by the MSSQL provider, these get filtered out, and an empty list is returned instead, causing the return valuess to be lost.
https://github.com/fsprojects/SQLProvider/blob/1fe76d3b7ddc81bb39a830e340a0f20d5a6a6cd7/src/SQLProvider.DesignTime/SqlDesignTime.fs#L126-L136
In further testing, I manually modified the schema cache file to be 2 instead of 6, I received an error that the type provider was attempting to create a member without a name. This is likely due to the MSSQL provider creating the return value parameter twice, one without a name, and one with the name ReturnValue
. When I changed the direction of the unnamed column back to 6 (as that was easier than trying to remove the first entry of the linked list), then everything compiles fine using the context schema file.
I believe a fix for this would be that either MSSQL provider (and possibly other providers, though I have not checked) change the direction of the query parameter to be output so that it can be picked up by the getSprocReturnColumns
function, or the getSprocReturnColumns
function needs to allow directions other than just Output
, such as InputOutput
and ReturnValue
, as it appears the MSSQL provider only provides parameters of these directions when it generates a list of return values and parameters.
https://github.com/fsprojects/SQLProvider/blob/1fe76d3b7ddc81bb39a830e340a0f20d5a6a6cd7/src/SQLProvider.Runtime/Providers.MsSqlServer.fs#L187-L188
Also, either the MSSQL provider should not create parameters for the return value twice, one without a name, and the other with the name ReturnValue
, or the getSprocReturnColumns
should filter out any parameter without a name, since a member cannot be created without a name.
Describe the bug When making use of context schema with MSSQL, scalar functions with a return value are assumed to return unit, rather than a type with a property
ReturnValue
containing the function's return value.To Reproduce Steps to reproduce the behavior:
SqlDataProvider
type referencing the database with a scalar valueExpected behavior The project should build the same as if no schema file were present
Desktop (please complete the following information):
Additional context TestFunction.sql
Program.fs
Test.schema
Error message