efcore: Net 5 Core Scaffold for SQL Server Calculated Fields doesn't emit ValueGeneratedOnAddOrUpdate()

Using Net Core RC 1 CLI the command: dotnet ef dbcontext scaffold Name=ConnectV3Connection Microsoft.EntityFrameworkCore.SqlServer

It doesn’t emit ValueGeneratedOnAddOrUpdate() for SQL Server calculated fields in the generated OnModelCreating method, nor does it generate an attribute if using the --data-annotations parameter.

For a quick fix I created a partial class for the Context and used the partial OnModelCreatingPartial(ModelBuilder builder) method and added the code:

entity.Property(e => e.ExtendedName).ValueGeneratedOnAddOrUpdate();

This situation was true for Preview 7 & 8 as well.

Thanks,

Scott

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 27 (18 by maintainers)

Most upvoted comments

Argh, it is a permissions issue, when I scaffold as DBOwner the HasComputedColumnSql call is emitted.

Nope, just my pride.

I am not sure this a regression.

EF Core 3.1.6:

                entity.Property(e => e.ExtendedName)
                    .IsRequired()
                    .HasMaxLength(62)
                    .HasComputedColumnSql("(([DepartmentCode]+': ')+[Name])");

EF Core 5 RC1:

                entity.Property(e => e.ExtendedName)
                    .IsRequired()
                    .HasMaxLength(62)
                    .HasComputedColumnSql("(([DepartmentCode]+': ')+[Name])", true);

Then yes, we should prepare the PR for rc2.

We actually reverse engineer persisted hence 2nd argument of HasComputedColumnSql is true.

HasComputedColumnSql round trips correctly and is scaffolded correctly.