From b0e653ab0d20b2db2df07843ad1cb3bd95a90f34 Mon Sep 17 00:00:00 2001 From: Kevin Matsubara Date: Mon, 7 Apr 2025 11:21:48 +0200 Subject: [PATCH] Add one to one relationship between Coach and Team. A Coach is parent, Team is child. A Coach can exist on his own, without a Team, but a Team cannot play without a Coach. --- EntityFrameworkCore.Domain/Coach.cs | 2 +- EntityFrameworkCore.Domain/Team.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/EntityFrameworkCore.Domain/Coach.cs b/EntityFrameworkCore.Domain/Coach.cs index b35c6b4..c7e4977 100644 --- a/EntityFrameworkCore.Domain/Coach.cs +++ b/EntityFrameworkCore.Domain/Coach.cs @@ -3,6 +3,6 @@ public class Coach : BaseDomainModel { public string Name { get; set; } // Strings are automatically become VARCHAR database types. - public int? TeamId { get; set; } + public Team? Team { get; set; } } diff --git a/EntityFrameworkCore.Domain/Team.cs b/EntityFrameworkCore.Domain/Team.cs index e6e8aa7..495aa34 100644 --- a/EntityFrameworkCore.Domain/Team.cs +++ b/EntityFrameworkCore.Domain/Team.cs @@ -5,7 +5,8 @@ public class Team : BaseDomainModel public string? Name { get; set; } public League? League { get; set; } public int? LeagueId { get; set; } + public Coach Coach { get; set; } public int CoachId { get; set; } - public List HomeMatches { get; set; } - public List AwayMatches { get; set; } + public List HomeMatches { get; set; } = new List() { }; + public List AwayMatches { get; set; } = new List() { }; }