diff --git a/EntityFrameworkCore.Data/Configurations/TeamConfiguration.cs b/EntityFrameworkCore.Data/Configurations/TeamConfiguration.cs index e479ce1..9dc1899 100644 --- a/EntityFrameworkCore.Data/Configurations/TeamConfiguration.cs +++ b/EntityFrameworkCore.Data/Configurations/TeamConfiguration.cs @@ -10,6 +10,11 @@ public class TeamConfiguration : IEntityTypeConfiguration { builder.HasIndex(t => t.Name).IsUnique(); + // example composite key configuration. + // builder.HasIndex(λ => new { λ.CoachId, λ.LeagueId }).IsUnique(); + + builder.Property(λ => λ.Name).HasMaxLength(100).IsRequired(); + builder.HasMany(m => m.HomeMatches) // A team has many home matches. .WithOne(m => m.HomeTeam) // Mapped to the HomeTeam property. .HasForeignKey(m => m.HomeTeamId) diff --git a/EntityFrameworkCore.Data/Migrations/DeadBallZoneLeagueDbContextModelSnapshot.cs b/EntityFrameworkCore.Data/Migrations/DeadBallZoneLeagueDbContextModelSnapshot.cs index 9c53654..c7135e5 100644 --- a/EntityFrameworkCore.Data/Migrations/DeadBallZoneLeagueDbContextModelSnapshot.cs +++ b/EntityFrameworkCore.Data/Migrations/DeadBallZoneLeagueDbContextModelSnapshot.cs @@ -37,6 +37,7 @@ namespace EntityFrameworkCore.Data.Migrations b.Property("Name") .IsRequired() + .HasMaxLength(100) .HasColumnType("TEXT"); b.HasKey("Id"); @@ -277,6 +278,8 @@ namespace EntityFrameworkCore.Data.Migrations .HasColumnType("TEXT"); b.Property("Name") + .IsRequired() + .HasMaxLength(100) .HasColumnType("TEXT"); b.HasKey("Id"); @@ -429,6 +432,19 @@ namespace EntityFrameworkCore.Data.Migrations }); }); + modelBuilder.Entity("EntityFrameworkCore.Domain.TeamsAndLeaguesView", b => + { + b.Property("LeagueName") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.ToTable((string)null); + + b.ToView("vw_TeamsAndLeagues", (string)null); + }); + modelBuilder.Entity("EntityFrameworkCore.Domain.Match", b => { b.HasOne("EntityFrameworkCore.Domain.Team", "AwayTeam") diff --git a/EntityFrameworkCore.Domain/Coach.cs b/EntityFrameworkCore.Domain/Coach.cs index c7e4977..8be3f85 100644 --- a/EntityFrameworkCore.Domain/Coach.cs +++ b/EntityFrameworkCore.Domain/Coach.cs @@ -1,7 +1,11 @@ -namespace EntityFrameworkCore.Domain; +using System.ComponentModel.DataAnnotations; + +namespace EntityFrameworkCore.Domain; // Since C#11, you do not need to wrap in accolades anymore. public class Coach : BaseDomainModel { + [MaxLength(100)] + [Required] public string Name { get; set; } // Strings are automatically become VARCHAR database types. public Team? Team { get; set; } }