Skip to content

Fix: Support Arrays in ComplexType#99

Open
tilicon wants to merge 2 commits into
UnoSD:masterfrom
tilicon:fix/support-array-in-complextype
Open

Fix: Support Arrays in ComplexType#99
tilicon wants to merge 2 commits into
UnoSD:masterfrom
tilicon:fix/support-array-in-complextype

Conversation

@tilicon

@tilicon tilicon commented Jun 3, 2026

Copy link
Copy Markdown

When using an implementation of ITypeHandler with SqlMapper.AddTypeHandler and the response model includes arrays of some sort, the array properties always come back as null.

I have added support for complex types to include array type of properties and they are now matched when returning the DataTable.

My sample self-contained test:

public class MyComplexType
{
    public int Id { get; set; }
    public string[] Names { get; set; }
}

[Test]
public void Test()
{
    var expected = new MyComplexType
    {
        Id = 1,
        Names = ["Name1", "Name2"],
    };

    var connection = new Mock<IDbConnection>();
    connection.SetupDapperAsync(c => c.QueryFirstOrDefaultAsync<MyComplexType>(It.IsAny<string>(), It.IsAny<object>(), It.IsAny<DbTransaction?>(), It.IsAny<int?>(), It.IsAny<CommandType?>()))
        .ReturnsAsync(expected);

    var actual = connection.Object.QueryFirstOrDefaultAsync<MyComplexType>("SELECT *")
        .GetAwaiter()
        .GetResult();

    Assert.AreEqual(expected.Names.Length, actual.Names.Length);
}

Timmy Lind added 2 commits June 3, 2026 12:46
@tilicon tilicon changed the title Fix Support Arrays in ComplexType Fix: Support Arrays in ComplexType Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant