-
Notifications
You must be signed in to change notification settings - Fork 54
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
If the casing of a SQL column name does not match the default property name returned by IEntityType.GetProperties(), scaffolding generates a HasColumnName call for both the original name returned from IEntityType.GetProperties(), as well as the actual database column name.
Expected behavior
Generate a single HasColumnName call with the correct SQL column name.
To Reproduce
Create and scaffold a database with SQL table (note that the identity column ends in "ID", all caps):
CREATE TABLE [dbo].[TestTable](
[TestTableID] [int] IDENTITY(1,1) NOT NULL,
[SomeOtherColumn] [nvarchar](10) NULL
) ON [PRIMARY]
In this case, IEntityType.GetProperties() will return a property called TestTableId ('d' is lower-case).
Using the following design time options:
public void ConfigureDesignTimeServices(IServiceCollection services)
{
services.AddHandlebarsScaffolding();
// Sample property renaming from EntityFrameworkCore.Scaffolding.Handlebars documentation
services.AddHandlebarsTransformers2(
// Rename EntityID to Id
propertyTransformer: (e, p) =>
$"{e.Name}Id" == p.PropertyName
? new EntityPropertyInfo(p.PropertyType, "ID", false)
: new EntityPropertyInfo(p.PropertyType, p.PropertyName, p.PropertyIsNullable));
}
Produces:
entity.Property(e => e.ID) // Correct new property name
.HasColumnName("TestTableId") // Incorrect: Default property name from EFCore.IEntityType.GetProperties
.ValueGeneratedOnAdd()
.HasColumnName("TestTableID"); // Correct SQL column name
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working