Skip to content

Allow to customize an alias in model binding #27296

@alexandis

Description

@alexandis

I've updated to EFCore 6.0 and now a lot of my queries are broken. The reason is that a lot of properties have the name which is a reserved word for our DB (I was not aware). Let's say:

builder.Entity<MyProperty>(b =>
{
    b.ToTable("MY_TABLE", CoreDbProperties.DbSchema);
    b.Property(x => x.Number).HasColumnName("C_NUMBER").IsRequired();
    ...
}

When Linq constructs the query - it names aliases after a property name and this breaks DB query.

To avoid nightmare with renaming tons of properties and doing regression testing afterwards, I suggest to make an alias customizable, like this:

builder.Entity<MyEntity>(b =>
{
    b.ToTable("MY_TABLE", CoreDbProperties.DbSchema);
    b.Property(x => x.Number).HasColumnName("C_NUMBER").HasAlias("MyNumber").IsRequired();
    ...
}

Metadata

Metadata

Assignees

No one assigned

    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