Skip to content

Commit

Permalink
Minor code fixes. Primarily avoiding capturing of key in GetOrAdd when
Browse files Browse the repository at this point in the history
parsing SQL.

A lot of simplification in query syntax via use of raw strings. Also
helps when verifying code-gen.
  • Loading branch information
sjp committed Mar 5, 2024
1 parent b03db1d commit 1a316b6
Show file tree
Hide file tree
Showing 82 changed files with 1,032 additions and 815 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public static void Generate_GivenValidSequence_ReturnsExpectedConfiguration()
Assert.That(result, Is.EqualTo(ExpectedSequenceTestResult).Using(LineEndingInvariantStringComparer.Ordinal));
}

private const string ExpectedSequenceTestResult = @"using System;
private const string ExpectedSequenceTestResult = """
using System;
using Microsoft.EntityFrameworkCore;
namespace test
Expand All @@ -91,11 +92,12 @@ public class AppContext : DbContext
/// <summary>
/// Configure the model that was discovered by convention from the defined entity types.
/// </summary>
/// <param name=""modelBuilder"">The builder being used to construct the model for this context.</param>
/// <param name="modelBuilder">The builder being used to construct the model for this context.</param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasSequence<decimal>(""test_sequence"").StartsAt(3M).IncrementsBy(20M);
modelBuilder.HasSequence<decimal>("test_sequence").StartsAt(3M).IncrementsBy(20M);
}
}
}";
}
""";
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public async Task ToString_GivenVariousTablesWithAnnotationsRequired_GeneratesEx
Assert.That(result, Is.EqualTo(expected).Using(LineEndingInvariantStringComparer.Ordinal));
}

private readonly string TestAppContextOutput = @"using System;
private readonly string TestAppContextOutput = """
using System;
using Microsoft.EntityFrameworkCore;
namespace EFCoreTestNamespace
Expand Down Expand Up @@ -132,29 +133,30 @@ public class AppContext : DbContext
/// <summary>
/// Configure the model that was discovered by convention from the defined entity types.
/// </summary>
/// <param name=""modelBuilder"">The builder being used to construct the model for this context.</param>
/// <param name="modelBuilder">The builder being used to construct the model for this context.</param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Main.TestTable1>().Property(t => t.TestDatetime).HasDefaultValue(""CURRENT_TIMESTAMP"");
modelBuilder.Entity<Main.TestTable1>().Property(t => t.TestStringWithDefault).HasDefaultValue(""'test'"");
modelBuilder.Entity<Main.TestTable1>().Property(t => t.TestDatetime).HasDefaultValue("CURRENT_TIMESTAMP");
modelBuilder.Entity<Main.TestTable1>().Property(t => t.TestStringWithDefault).HasDefaultValue("'test'");
modelBuilder.Entity<Main.TestTable1>().HasKey(t => t.TestPk);
modelBuilder.Entity<Main.TestTable2>().HasKey(t => new { t.TestPk1, t.TestPk2 }).HasName(""test_table_2_pk"");
modelBuilder.Entity<Main.TestTable2>().HasAlternateKey(t => new { t.FirstName, t.MiddleName, t.LastName }).HasName(""test_table_2_multi_uk"");
modelBuilder.Entity<Main.TestTable2>().HasIndex(t => t.LastName).IsUnique().HasDatabaseName(""ux_test_table_2_last_name"");
modelBuilder.Entity<Main.TestTable2>().HasIndex(t => new { t.FirstName, t.MiddleName }).IsUnique().HasDatabaseName(""ux_test_table_2_first_name_middle_name"");
modelBuilder.Entity<Main.TestTable2>().HasIndex(t => t.Comment).HasDatabaseName(""ix_test_table_2_comment"");
modelBuilder.Entity<Main.TestTable2>().HasIndex(t => new { t.FirstName, t.LastName }).HasDatabaseName(""ix_test_table_2_first_name"");
modelBuilder.Entity<Main.TestTable3>().Property(t => t.TestDatetime).HasDefaultValue(""CURRENT_TIMESTAMP"");
modelBuilder.Entity<Main.TestTable3>().Property(t => t.TestStringWithDefault).HasDefaultValue(""'test'"");
modelBuilder.Entity<Main.TestTable2>().HasKey(t => new { t.TestPk1, t.TestPk2 }).HasName("test_table_2_pk");
modelBuilder.Entity<Main.TestTable2>().HasAlternateKey(t => new { t.FirstName, t.MiddleName, t.LastName }).HasName("test_table_2_multi_uk");
modelBuilder.Entity<Main.TestTable2>().HasIndex(t => t.LastName).IsUnique().HasDatabaseName("ux_test_table_2_last_name");
modelBuilder.Entity<Main.TestTable2>().HasIndex(t => new { t.FirstName, t.MiddleName }).IsUnique().HasDatabaseName("ux_test_table_2_first_name_middle_name");
modelBuilder.Entity<Main.TestTable2>().HasIndex(t => t.Comment).HasDatabaseName("ix_test_table_2_comment");
modelBuilder.Entity<Main.TestTable2>().HasIndex(t => new { t.FirstName, t.LastName }).HasDatabaseName("ix_test_table_2_first_name");
modelBuilder.Entity<Main.TestTable3>().Property(t => t.TestDatetime).HasDefaultValue("CURRENT_TIMESTAMP");
modelBuilder.Entity<Main.TestTable3>().Property(t => t.TestStringWithDefault).HasDefaultValue("'test'");
modelBuilder.Entity<Main.TestTable3>().HasKey(t => t.TestPk);
modelBuilder.Entity<Main.TestTable4>().Property(t => t.TestDatetime).HasDefaultValue(""CURRENT_TIMESTAMP"");
modelBuilder.Entity<Main.TestTable4>().Property(t => t.TestStringWithDefault).HasDefaultValue(""'test'"");
modelBuilder.Entity<Main.TestTable4>().Property(t => t.TestDatetime).HasDefaultValue("CURRENT_TIMESTAMP");
modelBuilder.Entity<Main.TestTable4>().Property(t => t.TestStringWithDefault).HasDefaultValue("'test'");
modelBuilder.Entity<Main.TestTable4>().HasKey(t => t.TestPk);
modelBuilder.Entity<Main.TestTable4>().HasOne(t => t.TestTable3).WithMany(t => t!.TestTable4s).HasForeignKey(t => t.TestTable3Fk4).HasPrincipalKey(t => t!.TestPk).HasConstraintName(""fk_test_table_4_test_table_3_fk1"");
modelBuilder.Entity<Main.TestTable4>().HasOne(t => t.TestTable3).WithMany(t => t!.TestTable4s).HasForeignKey(t => t.TestTable3Fk3).HasPrincipalKey(t => t!.TestPk).HasConstraintName(""fk_test_table_4_test_table_3_fk1"");
modelBuilder.Entity<Main.TestTable4>().HasOne(t => t.TestTable3).WithMany(t => t!.TestTable4s).HasForeignKey(t => t.TestTable3Fk2).HasPrincipalKey(t => t!.TestPk).HasConstraintName(""fk_test_table_4_test_table_3_fk1"");
modelBuilder.Entity<Main.TestTable4>().HasOne(t => t.TestTable3).WithMany(t => t!.TestTable4s).HasForeignKey(t => t.TestTable3Fk1).HasPrincipalKey(t => t!.TestPk).HasConstraintName(""fk_test_table_4_test_table_3_fk1"");
modelBuilder.Entity<Main.TestTable4>().HasOne(t => t.TestTable3).WithMany(t => t!.TestTable4s).HasForeignKey(t => t.TestTable3Fk4).HasPrincipalKey(t => t!.TestPk).HasConstraintName("fk_test_table_4_test_table_3_fk1");
modelBuilder.Entity<Main.TestTable4>().HasOne(t => t.TestTable3).WithMany(t => t!.TestTable4s).HasForeignKey(t => t.TestTable3Fk3).HasPrincipalKey(t => t!.TestPk).HasConstraintName("fk_test_table_4_test_table_3_fk1");
modelBuilder.Entity<Main.TestTable4>().HasOne(t => t.TestTable3).WithMany(t => t!.TestTable4s).HasForeignKey(t => t.TestTable3Fk2).HasPrincipalKey(t => t!.TestPk).HasConstraintName("fk_test_table_4_test_table_3_fk1");
modelBuilder.Entity<Main.TestTable4>().HasOne(t => t.TestTable3).WithMany(t => t!.TestTable4s).HasForeignKey(t => t.TestTable3Fk1).HasPrincipalKey(t => t!.TestPk).HasConstraintName("fk_test_table_4_test_table_3_fk1");
}
}
}";
}
""";
}
Loading

0 comments on commit 1a316b6

Please sign in to comment.