Test Many to many
This commit is contained in:
@@ -7,6 +7,7 @@ namespace LaDOSE.Entity.Context
|
||||
public DbSet<Game> Game { get; set; }
|
||||
public DbSet<ApplicationUser> ApplicationUser { get; set; }
|
||||
public DbSet<Season> Season { get; set; }
|
||||
//public DbSet<SeasonGame> SeasonGame { get; set; }
|
||||
|
||||
public LaDOSEDbContext(DbContextOptions options) : base(options)
|
||||
{
|
||||
@@ -14,7 +15,24 @@ namespace LaDOSE.Entity.Context
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
modelBuilder.Entity<SeasonGame>()
|
||||
.HasKey(t => new { t.SeasonId, t.GameId });
|
||||
|
||||
|
||||
|
||||
modelBuilder.Entity<SeasonGame>()
|
||||
.HasOne(pt => pt.Season)
|
||||
.WithMany(p => p.Games)
|
||||
.HasForeignKey(pt => pt.GameId);
|
||||
|
||||
modelBuilder.Entity<SeasonGame>()
|
||||
.HasOne(pt => pt.Game)
|
||||
.WithMany(p => p.Seasons)
|
||||
.HasForeignKey(pt => pt.SeasonId);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LaDOSE.Entity
|
||||
{
|
||||
public class Game
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string ImgUrl { get; set; }
|
||||
|
||||
public virtual IEnumerable<SeasonGame> Seasons { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LaDOSE.Entity
|
||||
{
|
||||
public class Season
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public DateTime StartDate { get; set; }
|
||||
public DateTime EndDate { get; set; }
|
||||
|
||||
|
||||
public virtual IEnumerable<SeasonGame> Games { get; set; }
|
||||
}
|
||||
}
|
||||
11
LaDOSE.Src/LaDOSE.Entity/SeasonGame.cs
Normal file
11
LaDOSE.Src/LaDOSE.Entity/SeasonGame.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace LaDOSE.Entity
|
||||
{
|
||||
public class SeasonGame
|
||||
{
|
||||
public int GameId { get; set; }
|
||||
public Game Game { get; set; }
|
||||
public int SeasonId { get; set; }
|
||||
public Season Season { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user