diff --git a/EntityFrameworkCore.Data/Configurations/TeamConfiguration.cs b/EntityFrameworkCore.Data/Configurations/TeamConfiguration.cs index 88968b4..da59ae9 100644 --- a/EntityFrameworkCore.Data/Configurations/TeamConfiguration.cs +++ b/EntityFrameworkCore.Data/Configurations/TeamConfiguration.cs @@ -8,6 +8,20 @@ public class TeamConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { + builder.HasIndex(t => t.Name).IsUnique(); + + builder.HasMany(m => m.HomeMatches) // A team has many home matches. + .WithOne(m => m.HomeTeam) // Mapped to the HomeTeam property. + .HasForeignKey(m => m.HomeTeamId) + .IsRequired() + .OnDelete(DeleteBehavior.Restrict); + + builder.HasMany(m => m.AwayMatches) // A team has many home matches. + .WithOne(m => m.AwayTeam) // Mapped to the HomeTeam property. + .HasForeignKey(m => m.AwayTeamId) + .IsRequired() + .OnDelete(DeleteBehavior.Restrict); + builder.HasData( // Use hardcoded dates, not dynamic data such as new DateTimeOffset.UtcNow.DateTime for seeding. new Team { Id = 1, Name = "Neo Delhi", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33)}, diff --git a/EntityFrameworkCore.Domain/Match.cs b/EntityFrameworkCore.Domain/Match.cs index 359e964..abe7656 100644 --- a/EntityFrameworkCore.Domain/Match.cs +++ b/EntityFrameworkCore.Domain/Match.cs @@ -2,8 +2,12 @@ public class Match : BaseDomainModel { + public Team HomeTeam { get; set; } public int HomeTeamId { get; set; } + public int HomeTeamScore { get; set; } + public Team AwayTeam { get; set; } public int AwayTeamId { get; set; } + public int AwayTeamScore { get; set; } public decimal TicketPrice { get; set; } public DateTime Date { get; set; } } \ No newline at end of file diff --git a/EntityFrameworkCore.Domain/Team.cs b/EntityFrameworkCore.Domain/Team.cs index 1362461..e6e8aa7 100644 --- a/EntityFrameworkCore.Domain/Team.cs +++ b/EntityFrameworkCore.Domain/Team.cs @@ -6,4 +6,6 @@ public class Team : BaseDomainModel public League? League { get; set; } public int? LeagueId { get; set; } public int CoachId { get; set; } + public List HomeMatches { get; set; } + public List AwayMatches { get; set; } }