Mapping to tuple hides type incompatibilities
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
Hi,
I was wondering if this is an intentional feature or a bug.
Correct behavior I think:
If one uses a designated type (for example a record) to map the result set and there is a type difference between the desired destination's field type and the result set, it throws a runtime error as expected.
Questionable behavior:
In case one uses a tuple for mapping a result set of a query/stored procedure, type inconsistencies are hidden, not like the first case.
Example code:
[Fact]
public async Task Independent()
{
await using var connection = new SqlConnection("Data Source=localhost;Initial Catalog=test;TrustServerCertificate=True;Trusted_Connection=True");
await connection.OpenAsync();
//Tuple - No exception
var result1 = await connection.QueryAsync<(long IntegerColumn, int BigintColumn)>("SELECT IntegerColumn, BigintColumn FROM dbo.TestTable");
//With record - Correct mapping - No exception
var result3 = await connection.QueryAsync<TestResultCorrect>("SELECT IntegerColumn, BigintColumn FROM dbo.TestTable");
//With record - Incorrect mapping - Exception is thrown: A parameterless default constructor or one matching signature...
var result2 = await connection.QueryAsync<TestResultIncorrect>("SELECT IntegerColumn, BigintColumn FROM dbo.TestTable");
}
private record TestResultIncorrect(long IntegerColumn, int BigintColumn);
private record TestResultCorrect(int IntegerColumn, long BigintColumn);
Datatable:
create table dbo.TestTable
(
IntegerColumn int,
BigintColumn bigint
)
go
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the tuple and record QueryAsync cases against the shown dbo.TestTable schema, then trace the tuple-mapping path. Done means a regression test captures the intended handling of incompatible tuple field types and the behavior is consistent with record mapping.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100