Skip to content

Commit

Permalink
update to use EFCore.NamingConventions for snake_case db properties
Browse files Browse the repository at this point in the history
  • Loading branch information
William Denton committed Sep 22, 2019
1 parent 941bd35 commit 7d2ef0b
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 91 deletions.
8 changes: 4 additions & 4 deletions src/AwsRdsPostgresDemo/AwsRdsPostgresDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.RDS" Version="3.3.108.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.0.0-preview9.19423.6" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.0.0-preview9.19423.4" />
<PackageReference Include="AWSSDK.RDS" Version="3.3.110" />
<PackageReference Include="EFCore.NamingConventions" Version="1.0.0-rc1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.0.0-rc1.19456.10" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.0.0-preview9" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="3.0.0-preview9" />
</ItemGroup>
Expand All @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0-preview9.19423.6">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0-rc1.19456.14">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions src/AwsRdsPostgresDemo/Migrations/20190922075424_snake_case.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore.Migrations;

namespace WilliamDenton.AwsRdsPostgresDemo.Migrations
{
public partial class snake_case : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
// migrationBuilder.DropPrimaryKey(
// name: "pk_customers",
// table: "customers");

// migrationBuilder.AddPrimaryKey(
// name: "PK_customers",
// table: "customers",
// column: "id");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
// migrationBuilder.DropPrimaryKey(
// name: "PK_customers",
// table: "customers");

// migrationBuilder.AddPrimaryKey(
// name: "pk_customers",
// table: "customers",
// column: "id");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "3.0.0-preview9.19423.6")
.HasAnnotation("ProductVersion", "3.0.0-rc1.19456.14")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

modelBuilder.Entity("WilliamDenton.AwsRdsPostgresDemo.Models.Customer", b =>
Expand All @@ -41,8 +41,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("character varying(100)")
.HasMaxLength(100);

b.HasKey("Id")
.HasName("pk_customers");
b.HasKey("Id");

b.HasIndex("CustomerCode")
.IsUnique();
Expand Down
1 change: 0 additions & 1 deletion src/AwsRdsPostgresDemo/Models/DemoDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ protected DemoDbContext(DbContextOptions options) : base(options) { }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.UseSnakeCaseNames();

modelBuilder.Entity<Customer>()
.HasIndex(payment => payment.CustomerCode)
Expand Down
83 changes: 0 additions & 83 deletions src/AwsRdsPostgresDemo/Models/ModelBuilderExtensions.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/AwsRdsPostgresDemo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static void ConfigureDbContextOptions(DbContextOptionsBuilder efOptions, string
npgsqlOptions.UseAwsIamAuthentication();
npgsqlOptions.UseNodaTime();
});
efOptions.UseSnakeCaseNamingConventions();
}
services.AddScoped<IDemoReadWriteDbContext>(provider => provider.GetService<DemoReadWriteDbContext>());
services.AddScoped<IDemoReadOnlyDbContext>(provider => provider.GetService<DemoReadOnlyDbContext>());
Expand Down

0 comments on commit 7d2ef0b

Please sign in to comment.