This is a bit of an odd bug. I have the following entity, and the following tables (some stuff omitted)
CREATE TABLE [dbo].[MyEntity]
(
-- Some other columns as well, but the text column is the one that breaks
[ExtendedAttributes] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
When I try to insert something where the "ExtendedAttributes" text is longer than 16 characters, it's always truncated to 16 characters.
Reproducible example
// Entity, some stuff omitted
public class MyEntity
{
public string ExtendedAttributes { get; set; };
public int ID { get; set; }
}
// Test case
var entity = new MyEntity(id: 5, extendedAttributes: "123456789-123456789")
await using var connection = new SqlConnection("someConnectionString");
await connection.EnsureOpenAsync();
await connection.InsertAsync(entity);
var retrieved = await connection.QueryAllAsync<MyEntity>();
retrieved.First().Should().BeEquivalentTo(entity);
This results in the following error:
Expected member ExtendedAttributes to be
"123456789-123456789" with a length of 19, but
"123456789-123456" has a length of 16, differs near "6" (index 15).
I have checked that the value is also truncated in the database, so the issue is on the insertion part not the retrieval.
I have also done the following other steps to get more info:
- I have changed the text column to a varchar(255) - this makes it work
- I have put in a Trace. The arguments in the trace are the "correct" ones
- I have tried inserting it manually via the SqlConnection (without RepoDb) and it inserts it properly. I assume this means it's not a bug in the SQL Driver.
Potential reason
When debugging, I noticed that in InsertAsyncInternalBase, that the InsertExecutionContext.InputFields.ExtendedAttributes has the size set to 16, which is also what the string is truncated to. I don't know enough about the RepoDb codebase to understand if this is the real issue, but it seems like a promising start.
This is a bit of an odd bug. I have the following entity, and the following tables (some stuff omitted)
When I try to insert something where the "ExtendedAttributes" text is longer than 16 characters, it's always truncated to 16 characters.
Reproducible example
This results in the following error:
I have checked that the value is also truncated in the database, so the issue is on the insertion part not the retrieval.
I have also done the following other steps to get more info:
Potential reason
When debugging, I noticed that in
InsertAsyncInternalBase, that theInsertExecutionContext.InputFields.ExtendedAttributeshas the size set to 16, which is also what the string is truncated to. I don't know enough about the RepoDb codebase to understand if this is the real issue, but it seems like a promising start.