Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

trailing spaces in default values when scaffolding a database

JoelFromBoschOct 20 2021

It happens that we have trailing spaces in default values when scaffolding a database:
Sample table

CREATE TABLE "SCHEMA"."SAMPLE" 
(	
  TEST1 NUMBER(1) DEFAULT 0 NOT NULL,
  TIME_STAMP TIMESTAMP(6) WITH TIME ZONE DEFAULT current_timestamp NOT NULL,
  TEST2 NUMBER(1) DEFAULT 1,
)

Scaffolded c# code

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
  modelBuilder.Entity<Sample>(entity =>
  {
      entity.Property(e => e.Test2)
            .IsRequired()
            .HasPrecision(1)
            .HasColumnName("CLEANED")
            .HasDefaultValueSql("0 "); // Whitespace after default value
	
      entity.Property(e => e.TimeStamp)
            .HasColumnType("TIMESTAMP(6) WITH TIME ZONE")
            .ValueGeneratedOnAdd()
            .HasColumnName("TIME_STAMP")
            .HasDefaultValueSql("current_timestamp "); // Whitespace after default value
	
      entity.Property(e => e.Test1)
            .HasPrecision(1)
            .HasColumnName("TEST2")
            .HasDefaultValueSql("1");
  }
}

Only happens when the default value is followed by something else like " NOT NULL"
as it takes the default value including the trailing whitespace
image.png

This post has been answered by Alex Keh-Oracle on Nov 28 2023
Jump to Answer
Comments
Post Details
Added on Oct 20 2021
5 comments
199 views