Add relationship and foreign key configurations between Match and Team.
This commit is contained in:
parent
c73a72204d
commit
804943486f
@ -8,6 +8,20 @@ public class TeamConfiguration : IEntityTypeConfiguration<Team>
|
|||||||
{
|
{
|
||||||
public void Configure(EntityTypeBuilder<Team> builder)
|
public void Configure(EntityTypeBuilder<Team> 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(
|
builder.HasData(
|
||||||
// Use hardcoded dates, not dynamic data such as new DateTimeOffset.UtcNow.DateTime for seeding.
|
// 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)},
|
new Team { Id = 1, Name = "Neo Delhi", CreatedDate = new DateTime(2025, 4, 4, 17, 7, 27, 33)},
|
||||||
|
|||||||
@ -2,8 +2,12 @@
|
|||||||
|
|
||||||
public class Match : BaseDomainModel
|
public class Match : BaseDomainModel
|
||||||
{
|
{
|
||||||
|
public Team HomeTeam { get; set; }
|
||||||
public int HomeTeamId { get; set; }
|
public int HomeTeamId { get; set; }
|
||||||
|
public int HomeTeamScore { get; set; }
|
||||||
|
public Team AwayTeam { get; set; }
|
||||||
public int AwayTeamId { get; set; }
|
public int AwayTeamId { get; set; }
|
||||||
|
public int AwayTeamScore { get; set; }
|
||||||
public decimal TicketPrice { get; set; }
|
public decimal TicketPrice { get; set; }
|
||||||
public DateTime Date { get; set; }
|
public DateTime Date { get; set; }
|
||||||
}
|
}
|
||||||
@ -6,4 +6,6 @@ public class Team : BaseDomainModel
|
|||||||
public League? League { get; set; }
|
public League? League { get; set; }
|
||||||
public int? LeagueId { get; set; }
|
public int? LeagueId { get; set; }
|
||||||
public int CoachId { get; set; }
|
public int CoachId { get; set; }
|
||||||
|
public List<Match> HomeMatches { get; set; }
|
||||||
|
public List<Match> AwayMatches { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user