Skip to content

Commit

Permalink
Add FK Constraings and Compound Key to AP
Browse files Browse the repository at this point in the history
  • Loading branch information
amos-cha committed Jul 24, 2023
1 parent cc31b3c commit 1c8d06a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
8 changes: 4 additions & 4 deletions Gordon360/Models/CCT/Context/CCTContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,22 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<AffiliationPoints>(entity =>
{
entity.Property(e => e.Points).HasDefaultValueSql("((0))");
entity.HasKey(e => new { e.AffiliationName, e.TeamID, e.SeriesID });
entity.HasOne(d => d.AffiliationNameNavigation)
.WithMany()
.WithMany(p => p.AffiliationPoints)
.HasForeignKey(d => d.AffiliationName)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_AffiliationPoints_Affiliations");
entity.HasOne(d => d.Series)
.WithMany()
.WithMany(p => p.AffiliationPoints)
.HasForeignKey(d => d.SeriesID)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_AffiliationPoints_Series");
entity.HasOne(d => d.Team)
.WithMany()
.WithMany(p => p.AffiliationPoints)
.HasForeignKey(d => d.TeamID)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("FK_AffiliationPoints_Team");
Expand Down
3 changes: 3 additions & 0 deletions Gordon360/Models/CCT/RecIM/Affiliation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public partial class Affiliation
{
public Affiliation()
{
AffiliationPoints = new HashSet<AffiliationPoints>();
Team = new HashSet<Team>();
}

Expand All @@ -21,6 +22,8 @@ public Affiliation()
[Unicode(false)]
public string Name { get; set; }

[InverseProperty("AffiliationNameNavigation")]
public virtual ICollection<AffiliationPoints> AffiliationPoints { get; set; }
[InverseProperty("AffiliationNavigation")]
public virtual ICollection<Team> Team { get; set; }
}
Expand Down
10 changes: 7 additions & 3 deletions Gordon360/Models/CCT/RecIM/AffiliationPoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@

namespace Gordon360.Models.CCT
{
[Keyless]
[Table("AffiliationPoints", Schema = "RecIM")]
public partial class AffiliationPoints
{
[Required]
[Key]
[StringLength(50)]
[Unicode(false)]
public string AffiliationName { get; set; }
[Key]
public int TeamID { get; set; }
[Key]
public int SeriesID { get; set; }
public int? Points { get; set; }
public int Points { get; set; }

[ForeignKey("AffiliationName")]
[InverseProperty("AffiliationPoints")]
public virtual Affiliation AffiliationNameNavigation { get; set; }
[ForeignKey("SeriesID")]
[InverseProperty("AffiliationPoints")]
public virtual Series Series { get; set; }
[ForeignKey("TeamID")]
[InverseProperty("AffiliationPoints")]
public virtual Team Team { get; set; }
}
}
3 changes: 3 additions & 0 deletions Gordon360/Models/CCT/RecIM/Series.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public partial class Series
{
public Series()
{
AffiliationPoints = new HashSet<AffiliationPoints>();
Match = new HashSet<Match>();
SeriesSurface = new HashSet<SeriesSurface>();
SeriesTeam = new HashSet<SeriesTeam>();
Expand Down Expand Up @@ -51,6 +52,8 @@ public Series()
[InverseProperty("Series")]
public virtual Team Winner { get; set; }
[InverseProperty("Series")]
public virtual ICollection<AffiliationPoints> AffiliationPoints { get; set; }
[InverseProperty("Series")]
public virtual ICollection<Match> Match { get; set; }
[InverseProperty("Series")]
public virtual ICollection<SeriesSurface> SeriesSurface { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions Gordon360/Models/CCT/RecIM/Team.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public partial class Team
{
public Team()
{
AffiliationPoints = new HashSet<AffiliationPoints>();
MatchParticipant = new HashSet<MatchParticipant>();
MatchTeam = new HashSet<MatchTeam>();
ParticipantTeam = new HashSet<ParticipantTeam>();
Expand Down Expand Up @@ -45,6 +46,8 @@ public Team()
[InverseProperty("Team")]
public virtual TeamStatus Status { get; set; }
[InverseProperty("Team")]
public virtual ICollection<AffiliationPoints> AffiliationPoints { get; set; }
[InverseProperty("Team")]
public virtual ICollection<MatchParticipant> MatchParticipant { get; set; }
[InverseProperty("Team")]
public virtual ICollection<MatchTeam> MatchTeam { get; set; }
Expand Down

0 comments on commit 1c8d06a

Please sign in to comment.