Efcore: Reverse Engineering generates not needed code

Created on 25 Nov 2020  路  8Comments  路  Source: dotnet/efcore

.NET CLI Tools: 5.0.0

Generated code:

entity.Property(e => e.ChangedDate)
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("('2014-07-22T10:34:48.440Z')")
                    .HasAnnotation("Relational:ColumnType", "datetime");

Should be:

entity.Property(e => e.ChangedDate)
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("('2014-07-22T10:34:48.440Z')"));

Generated code:

entity.Property(e => e.OperationArt)
                    .IsRequired()
                    .HasMaxLength(1)
                    .IsFixedLength(true);

Should be (default parameter value for IsFixedLength() is true):

entity.Property(e => e.OperationArt)
                    .IsRequired()
                    .HasMaxLength(1)
                    .IsFixedLength();
area-scaffolding customer-reported good first issue type-enhancement

Most helpful comment

ColumnType annotation is already removed from scaffolded code in 5.0 release. See https://github.com/dotnet/efcore/issues/22564
Have you upgraded all your packages and tooling to 5.0 RTM?

All 8 comments

Which provider?

ColumnType annotation is already removed from scaffolded code in 5.0 release. See https://github.com/dotnet/efcore/issues/22564
Have you upgraded all your packages and tooling to 5.0 RTM?

@ErikEJ: Microsoft.EntityFrameworkCore.SqlServer

@smitpatel: Ahhh sorry, I was on wrong branch (RC1). You are right.

Still in TODO: .IsFixedLength(true)

@Saibamen Please post the database schema that results in reverse engineering to .IsFixedLength(true) where it is not needed so that we can investigate.

@ajcvickers This method is needed.

What is not needed is true parameter, because true is the default value for IsFixedLength() ;)

In short: .IsFixedLength(true) should (could ;)) be .IsFixedLength(). This same behavior, but less generated code.

image

Hi @ajcvickers . I would like to fix this issue as a first contribution to this library.

Hi @ajcvickers . Can you please provide some pointers on the class/method that needs to be fixed?

@ramanathanv CSharpDbContextGenerator is the class the controls code generation of the DbContext. It looks like IsFixedLength comes from AnnotationCodeGenerator.

Was this page helpful?
0 / 5 - 0 ratings