Conversion failed when using User Defined Table Types
@smoothdeveloper ci sta già lavorando.
Dal 29/11/2022.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Issue Summary
When using a User Defined Table Type it appears to write the value to the wrong column, resulting in a database conversion error. Using the SQL profiler I can see this error occurs before executing the SQL and only when the @Parameter has one or more items. If it is empty or removed the command executes successfully.
Error
System.Data.SqlClient.SqlException: 'Conversion failed when converting the nvarchar value 'TestName' to data type int.
The statement has been terminated.'
To Reproduce
Possibly share SQL Schema, snippets of data, and how you call it in F#.
Sample to reproduce the behavior:
Table and Table Type
Create Table [TestTable] (
[C1] UniqueIdentifier Not Null,
[C2] UniqueIdentifier Not Null,
[C3] UniqueIdentifier Not Null,
[C4] NVarChar(100) Not Null,
[C5] NVarChar(100) Not Null,
[C6] NVarChar(100) Null,
[C7] NVarChar(1000) Not Null,
[C8] Int Not Null,
[C9] VarChar(10) Not Null,
[C10] UniqueIdentifier Not Null,
[C11] UniqueIdentifier Not Null,
Constraint [PK_Id] Primary Key Clustered([C1], [C2], [C3])
);
Create Type [dbo].[TestTableItem] AS Table(
[C3] UniqueIdentifier Not Null,
[C5] NVarChar(100) Not Null,
[C6] NVarChar(100) Null,
[C7] NVarChar(1000) Not Null,
[C8] Int Not Null,
[C9] VarChar(10) Not Null,
[C10] UniqueIdentifier Not Null
);
SqlCommandProvider
type AddSqlCommand = SqlCommandProvider<"
Insert [TestTable]
(
[C1],
[C2],
[C11],
[C4],
[C2],
[C5],
[C6],
[C7],
[C8],
[C9],
[C10]
)
Select
@C1,
@C2,
@C11,
@C4,
x.[C3],
x.[C5],
x.[C6],
x.[C7],
x.[C8],
x.[C9],
x.[C10]
From @C12 x;
" , staticConnectionString, TableVarMapping = "@C12=TestTableItem">
Usage
use cmd = new AddSqlCommand(connection, transaction = transaction)
let items =
[
AddSqlCommand.TestTableItem(
C3 = Guid.NewGuid(),
C5 = "TestName",
C6 = "C6",
C7 = "C7",
C8 = 1,
C9 = "C9",
C10 = Guid.NewGuid()
)
]
return!
cmd.AsyncExecute(
C1 = Guid.NewGuid(),
C2 = Guid.NewGuid(),
C4 = "C4 Name",
C11 = Guid.NewGuid(),
C12 = items
)
Expected behavior
The query should successfully insert a new row.
What you can do
- I am willing to contribute a PR with a unit test showcasing the issue
- I am willing to test the bug fix before next release
- Lingua principale
- F#
- Stelle
- 206
- Fork
- 66
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di fsprojects/FSharp.Data.SqlClient
-
Document agentic contribution workflowForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
-
can't use SQL2025 for design timeForse di nuovo libera @smoothdeveloper l’ha presa 78 giorni fa e non c’è nessuna pull request aperta. Aperta
fsprojects/FSharp.Data.SqlClient#484 · 3 commenti · 1 assegnatario ·
-
Requirements going forward?Apertaenhancement question
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
fsprojects/FSharp.Data.SqlClient#445 · 9 commenti ·
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 45/100
fsprojects/FSharp.Data.SqlClient#429 · 5 commenti ·
-
NullReferenceException in SqlConnection.UseLocallyForse di nuovo libera @smoothdeveloper l’ha presa 1211 giorni fa e non c’è nessuna pull request aperta. Apertabug
fsprojects/FSharp.Data.SqlClient#428 · 2 commenti · 1 assegnatario ·