Skip to content

Commit

Permalink
use non virtual properties for navigational properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Barsonax committed May 21, 2024
1 parent ca5e102 commit 99f13be
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 35 deletions.

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

126 changes: 126 additions & 0 deletions CleanAspCore/Data/Migrations/20240521195118_InitialMigration2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace CleanAspCore.Migrations
{
/// <inheritdoc />
public partial class InitialMigration2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "Jobs",
type: "character varying(100)",
maxLength: 100,
nullable: false,
oldClrType: typeof(string),
oldType: "text");

migrationBuilder.AlterColumn<string>(
name: "LastName",
table: "Employees",
type: "character varying(100)",
maxLength: 100,
nullable: false,
oldClrType: typeof(string),
oldType: "text");

migrationBuilder.AlterColumn<string>(
name: "Gender",
table: "Employees",
type: "character varying(100)",
maxLength: 100,
nullable: false,
oldClrType: typeof(string),
oldType: "text");

migrationBuilder.AlterColumn<string>(
name: "FirstName",
table: "Employees",
type: "character varying(100)",
maxLength: 100,
nullable: false,
oldClrType: typeof(string),
oldType: "text");

migrationBuilder.AlterColumn<string>(
name: "Name",
table: "Departments",
type: "character varying(100)",
maxLength: 100,
nullable: false,
oldClrType: typeof(string),
oldType: "text");

migrationBuilder.AlterColumn<string>(
name: "City",
table: "Departments",
type: "character varying(100)",
maxLength: 100,
nullable: false,
oldClrType: typeof(string),
oldType: "text");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "Jobs",
type: "text",
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(100)",
oldMaxLength: 100);

migrationBuilder.AlterColumn<string>(
name: "LastName",
table: "Employees",
type: "text",
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(100)",
oldMaxLength: 100);

migrationBuilder.AlterColumn<string>(
name: "Gender",
table: "Employees",
type: "text",
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(100)",
oldMaxLength: 100);

migrationBuilder.AlterColumn<string>(
name: "FirstName",
table: "Employees",
type: "text",
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(100)",
oldMaxLength: 100);

migrationBuilder.AlterColumn<string>(
name: "Name",
table: "Departments",
type: "text",
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(100)",
oldMaxLength: 100);

migrationBuilder.AlterColumn<string>(
name: "City",
table: "Departments",
type: "text",
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(100)",
oldMaxLength: 100);
}
}
}
55 changes: 22 additions & 33 deletions CleanAspCore/Data/Migrations/HrContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,28 @@ protected override void BuildModel(ModelBuilder modelBuilder)

NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);

modelBuilder.Entity("CleanAspCore.Data.Models.Department", b =>
modelBuilder.Entity("CleanAspCore.Data.Models.Departments.Department", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");

b.Property<string>("City")
.IsRequired()
.HasColumnType("text");
.HasMaxLength(100)
.HasColumnType("character varying(100)");

b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
.HasMaxLength(100)
.HasColumnType("character varying(100)");

b.HasKey("Id");

b.ToTable("Departments");
});

modelBuilder.Entity("CleanAspCore.Data.Models.Employee", b =>
modelBuilder.Entity("CleanAspCore.Data.Models.Employees.Employee", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
Expand All @@ -50,20 +52,27 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<Guid>("DepartmentId")
.HasColumnType("uuid");

b.Property<string>("FirstName")
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");

b.Property<string>("FirstName")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)");

b.Property<string>("Gender")
.IsRequired()
.HasColumnType("text");
.HasMaxLength(100)
.HasColumnType("character varying(100)");

b.Property<Guid>("JobId")
.HasColumnType("uuid");

b.Property<string>("LastName")
.IsRequired()
.HasColumnType("text");
.HasMaxLength(100)
.HasColumnType("character varying(100)");

b.HasKey("Id");

Expand All @@ -74,58 +83,38 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("Employees");
});

modelBuilder.Entity("CleanAspCore.Data.Models.Job", b =>
modelBuilder.Entity("CleanAspCore.Data.Models.Jobs.Job", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");

b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
.HasMaxLength(100)
.HasColumnType("character varying(100)");

b.HasKey("Id");

b.ToTable("Jobs");
});

modelBuilder.Entity("CleanAspCore.Data.Models.Employee", b =>
modelBuilder.Entity("CleanAspCore.Data.Models.Employees.Employee", b =>
{
b.HasOne("CleanAspCore.Data.Models.Department", "Department")
b.HasOne("CleanAspCore.Data.Models.Departments.Department", "Department")
.WithMany()
.HasForeignKey("DepartmentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.HasOne("CleanAspCore.Data.Models.Job", "Job")
b.HasOne("CleanAspCore.Data.Models.Jobs.Job", "Job")
.WithMany()
.HasForeignKey("JobId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.OwnsOne("CleanAspCore.Domain.EmailAddress", "Email", b1 =>
{
b1.Property<Guid>("EmployeeId")
.HasColumnType("uuid");

b1.Property<string>("Email")
.IsRequired()
.HasColumnType("text")
.HasColumnName("Email");

b1.HasKey("EmployeeId");

b1.ToTable("Employees");

b1.WithOwner()
.HasForeignKey("EmployeeId");
});

b.Navigation("Department");

b.Navigation("Email")
.IsRequired();

b.Navigation("Job");
});
#pragma warning restore 612, 618
Expand Down
16 changes: 16 additions & 0 deletions CleanAspCore/Data/Models/Departments/DepartmentConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace CleanAspCore.Data.Models.Departments;

internal sealed class DepartmentConfiguration : IEntityTypeConfiguration<Department>
{
public void Configure(EntityTypeBuilder<Department> builder)
{
builder.Property(c => c.Name)
.HasMaxLength(100);

builder.Property(c => c.City)
.HasMaxLength(100);
}
}
Loading

0 comments on commit 99f13be

Please sign in to comment.