Skip to content

Bug: ColumnTypes defined in Entity Configuration are not properly translated into SQL #24

@Felixzed

Description

@Felixzed

Bug Report

HasColumnType annotations Enum8(...), Enum16(...) and AggregateFunction(...) in EntityConfigurations are not respected and always default to String type. I will be submitting a pull request along with my feature request.

Current behavior

Defining an EFCore Entity Configuration such that:

public class UsersTable
{
	public override void Configure(EntityTypeBuilder<DailyActiveUsers> builder)
	{
		base.Configure(builder);
		builder.Property(x => x.User)
			.HasColumnType("AggregateFunction(uniq, UInt64)")
			.HasColumnName("User");
	}
}

Or:

public class UsersTable
{
	public override void Configure(EntityTypeBuilder<FooBar> builder)
	{
		base.Configure(builder);
                builder.Property(x => x.User)
                           .HasColumnName("User")
                           .HasColumnType("Enum8('Foo' = 0, 'Bar' = 1")
                           .IsRequired();
	}
}


and using both those entity configurations in an EFCore migration produces the following migration code:
(for both cases)

...
migrationBuilder.CreateTable(
    name: "users_table",
    schema: "default",
    columns: table => new
    {
        User = table.Column<String>(type: "string", nullable: false)
    },
...

Which fails on the ensure schema operation, saying schemas are not supported. This makes it difficult define database structure in EFCore.

Expected behavior

public class UsersTable
{
	public override void Configure(EntityTypeBuilder<FooBar> builder)
	{
		base.Configure(builder);
		builder.Property(x => x.User)
			.HasColumnType("AggregateFunction(uniq, UInt64)")
			.HasColumnName("User");
	}
}

AND

public class UsersTable
{
	public override void Configure(EntityTypeBuilder<FooBar> builder)
	{
		base.Configure(builder);
                builder.Property(x => x.User)
                           .HasColumnName("User")
                           .HasColumnType("Enum8('Foo' = 0, 'Bar' = 1")
                           .IsRequired();
	}
}

// Should translate to:

CREATE TABLE `User` (                                                                                                                                                                                                                                                                                                                                                                                    
    `User` AggregateFunction(uniq, UInt64)                                                                                                                                                                                                                 
)                                                                                                                                                                                                                                           

AND

CREATE TABLE `User` (                                                                                                                                                                                                                                                                                                                                                                                    
    `User` Enum8('Foo' = 0, 'Bar' = 1)                                                                                                                                                                                                                 
)                                                                                                                                                                                                                                           

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions