Skip to content

Cannot map nullable types to FlatTableProjections #3400

Open
@nathanjcollins

Description

When I use a FlatTableProjection, I cannot use non string nullables.

public record ImportFailedWithStringErrorCode(string? ErrorCodeString);

public record ImportFailedWithGuidErrorCode(Guid? ErrorCodeGuid);

public class FlatImportProjection : FlatTableProjection
{
    public FlatImportProjection()
        : base("import_history", SchemaNameSource.EventSchema)
    {
        Table.AddColumn<Guid>("id").AsPrimaryKey();

        TeardownDataOnRebuild = true;

        Project<ImportStarted>(map =>
        {
            map.Map(x => x.Started);
        });

        Project<ImportFailedWithStringErrorCode>(map =>
        {
            map.Map(x => x.ErrorCodeString);
        });

        Project<ImportFailedWithGuidErrorCode>(map =>
        {
            map.Map(x => x.ErrorCodeGuid);
        });
    }
}

If an event of ImportFailedWithGuidErrorCode is created with null, it will fail with the following error:

MessageText: function ms.mt_upsert_import_history_importfailedwithguiderrorcode(uuid, text) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.

ImportFailedWithStringErrorCode works when passing null.

We have also tried other types, but it only seems to work with nullable strings.

There is a workaround using raw sql, but it's not ideal:

        ops.QueueSqlCommand(
            $"""
            insert into {TableName} (
                ErrorCodeGuid
            )
            values (
                ?::uuid /* note we have to explicitly cast it to a uuid here */
            )
            """,
            e.Data.ErrorCodeGuid?.ToString()!
        );

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions