msawczyn/EFDesigner

Error generating column type

tdabek opened this issue · 3 comments

Hello,

I believe there is an error in generating column type. Setting different value than default produces duplicated HasColumnType call in EF Core:

modelBuilder.Entity<Test>()  
                     .Property(t => t.Template)  
                     .IsRequired()  
                     .HasColumnType("json");  
                     .HasColumnType("json");

The problem is with EFCoreDesigner.ttinclude file, line 331 and 332:

if (modelAttribute.ColumnType != "default")
            segments.Add($"HasColumnType(\"{modelAttribute.ColumnType}\");");

These lines should be removed, because in 335:

if (modelAttribute.ColumnType.ToLowerInvariant() != "default")
         {
            if (modelAttribute.ColumnType.ToLowerInvariant() == "varchar" || modelAttribute.ColumnType.ToLowerInvariant() == "char")
               segments.Add($"HasColumnType(\"{modelAttribute.ColumnType}({modelAttribute.MaxLength})\")");
            else
               segments.Add($"HasColumnType(\"{modelAttribute.ColumnType}\")");
         }

Removing these two lines from EFCoreDesigner.ttinclude on my local machine solved this issue.

Thanks for the report ... and the PR for the fix! I'll have that in the next release.

1.2.7 pre-release is in the releases. Could you take a peek and see if this resolves your issue? Thanks!

Fixed and released in 1.2.7.1. Closing issue.