-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e232c0
commit 44e4d2a
Showing
48 changed files
with
1,925 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+463 KB
05.Entity Relations/05. DB-Advanced-EF-Core-Entity-Relations-Exercises.docx
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28307.136 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P03_FootballBetting", "P03_FootballBetting\P03_FootballBetting.csproj", "{2EF6C49E-1FE3-4301-8481-2FFAF0E199CC}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{2EF6C49E-1FE3-4301-8481-2FFAF0E199CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{2EF6C49E-1FE3-4301-8481-2FFAF0E199CC}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{2EF6C49E-1FE3-4301-8481-2FFAF0E199CC}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{2EF6C49E-1FE3-4301-8481-2FFAF0E199CC}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {FB86C300-E61C-4C4C-BD30-9BA95C6354EB} | ||
EndGlobalSection | ||
EndGlobal |
23 changes: 23 additions & 0 deletions
23
...tity Relations/BookmakerSystem/P03_FootballBetting/Data/EntityConfigurations/BetConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace P03_FootballBetting.Data.EntityConfigurations | ||
{ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
using P03_FootballBetting.Data.Models; | ||
|
||
public class BetConfig : IEntityTypeConfiguration<Bet> | ||
{ | ||
public void Configure(EntityTypeBuilder<Bet> builder) | ||
{ | ||
builder.HasKey(b => b.BetId); | ||
|
||
builder.HasOne(b => b.Game) | ||
.WithMany(g => g.Bets) | ||
.HasForeignKey(b => b.GameId); | ||
|
||
builder.HasOne(b => b.User) | ||
.WithMany(u => u.Bets) | ||
.HasForeignKey(b => b.UserId); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ity Relations/BookmakerSystem/P03_FootballBetting/Data/EntityConfigurations/GameConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace P03_FootballBetting.Data.EntityConfigurations | ||
{ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
using P03_FootballBetting.Data.Models; | ||
|
||
public class GameConfig : IEntityTypeConfiguration<Game> | ||
{ | ||
public void Configure(EntityTypeBuilder<Game> builder) | ||
{ | ||
builder.HasKey(g => g.GameId); | ||
|
||
builder.HasOne(g => g.HomeTeam) | ||
.WithMany(t => t.HomeGames) | ||
.HasForeignKey(g => g.HomeTeamId) | ||
.OnDelete(DeleteBehavior.Restrict); | ||
|
||
builder.HasOne(g => g.AwayTeam) | ||
.WithMany(t => t.AwayGames) | ||
.HasForeignKey(g => g.AwayTeamId) | ||
.OnDelete(DeleteBehavior.Restrict); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...y Relations/BookmakerSystem/P03_FootballBetting/Data/EntityConfigurations/PlayerConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace P03_FootballBetting.Data.EntityConfigurations | ||
{ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
using P03_FootballBetting.Data.Models; | ||
|
||
public class PlayerConfig : IEntityTypeConfiguration<Player> | ||
{ | ||
public void Configure(EntityTypeBuilder<Player> builder) | ||
{ | ||
builder.HasKey(p => p.PlayerId); | ||
|
||
builder.HasOne(p => p.Team) | ||
.WithMany(t => t.Players) | ||
.HasForeignKey(p => p.TeamId); | ||
|
||
builder.HasOne(p => p.Position) | ||
.WithMany(p => p.Players) | ||
.HasForeignKey(p => p.PositionId); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ns/BookmakerSystem/P03_FootballBetting/Data/EntityConfigurations/PlayerStatisticConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace P03_FootballBetting.Data.EntityConfigurations | ||
{ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
using P03_FootballBetting.Data.Models; | ||
|
||
public class PlayerStatisticConfig : IEntityTypeConfiguration<PlayerStatistic> | ||
{ | ||
public void Configure(EntityTypeBuilder<PlayerStatistic> builder) | ||
{ | ||
builder.HasKey(ps => new { ps.GameId, ps.PlayerId }); | ||
|
||
builder.HasOne(ps => ps.Game) | ||
.WithMany(g => g.PlayerStatistics) | ||
.HasForeignKey(ps => ps.GameId); | ||
|
||
builder.HasOne(ps => ps.Player) | ||
.WithMany(p => p.PlayerStatistics) | ||
.HasForeignKey(ps => ps.PlayerId); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ity Relations/BookmakerSystem/P03_FootballBetting/Data/EntityConfigurations/TeamConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace P03_FootballBetting.Data.EntityConfigurations | ||
{ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
using P03_FootballBetting.Data.Models; | ||
|
||
public class TeamConfig : IEntityTypeConfiguration<Team> | ||
{ | ||
public void Configure(EntityTypeBuilder<Team> builder) | ||
{ | ||
builder.HasKey(e => e.TeamId); | ||
|
||
builder.HasOne(e => e.PrimaryKitColor) | ||
.WithMany(pkc => pkc.PrimaryKitTeams) | ||
.HasForeignKey(e => e.PrimaryKitColorId) | ||
.OnDelete(DeleteBehavior.Restrict); | ||
|
||
builder.HasOne(e => e.SecondaryKitColor) | ||
.WithMany(skc => skc.SecondaryKitTeams) | ||
.HasForeignKey(e => e.SecondaryKitColorId) | ||
.OnDelete(DeleteBehavior.Restrict); | ||
|
||
builder.HasOne(e => e.Town) | ||
.WithMany(t => t.Teams) | ||
.HasForeignKey(e => e.TownId); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ity Relations/BookmakerSystem/P03_FootballBetting/Data/EntityConfigurations/TownConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace P03_FootballBetting.Data.EntityConfigurations | ||
{ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
using P03_FootballBetting.Data.Models; | ||
|
||
public class TownConfig : IEntityTypeConfiguration<Town> | ||
{ | ||
public void Configure(EntityTypeBuilder<Town> builder) | ||
{ | ||
builder.HasKey(t => t.TownId); | ||
|
||
builder.HasOne(t => t.Country) | ||
.WithMany(c => c.Towns) | ||
.HasForeignKey(t => t.CountryId); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
05.Entity Relations/BookmakerSystem/P03_FootballBetting/Data/FootballBettingContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
namespace P03_FootballBetting.Data | ||
{ | ||
using System; | ||
using System.IO; | ||
|
||
using Microsoft.EntityFrameworkCore; | ||
|
||
using P03_FootballBetting.Data.EntityConfigurations; | ||
using P03_FootballBetting.Data.Models; | ||
|
||
public class FootballBettingContext : DbContext | ||
{ | ||
public FootballBettingContext() { } | ||
|
||
public FootballBettingContext(DbContextOptions options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
public DbSet<Bet> Bets { get; set; } | ||
|
||
public DbSet<User> Users { get; set; } | ||
|
||
public DbSet<Game> Games { get; set; } | ||
|
||
public DbSet<PlayerStatistic> PlayerStatistics { get; set; } | ||
|
||
public DbSet<Player> Players { get; set; } | ||
|
||
public DbSet<Team> Teams { get; set; } | ||
|
||
public DbSet<Color> Colors { get; set; } | ||
|
||
public DbSet<Country> Countries { get; set; } | ||
|
||
public DbSet<Town> Towns { get; set; } | ||
|
||
public DbSet<Position> Positions { get; set; } | ||
|
||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
if (!optionsBuilder.IsConfigured) | ||
{ | ||
var path = Path.Combine(Environment.CurrentDirectory, @"C:\Users\Pavel\ConnectionString.txt"); | ||
optionsBuilder.UseSqlServer(File.ReadAllText(path)); | ||
} | ||
} | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.ApplyConfiguration(new BetConfig()); | ||
modelBuilder.ApplyConfiguration(new GameConfig()); | ||
modelBuilder.ApplyConfiguration(new PlayerConfig()); | ||
modelBuilder.ApplyConfiguration(new PlayerStatisticConfig()); | ||
modelBuilder.ApplyConfiguration(new TeamConfig()); | ||
modelBuilder.ApplyConfiguration(new TownConfig()); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
05.Entity Relations/BookmakerSystem/P03_FootballBetting/Data/Models/Bet.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace P03_FootballBetting.Data.Models | ||
{ | ||
using System; | ||
|
||
public class Bet | ||
{ | ||
public int BetId { get; set; } | ||
|
||
public decimal Amount { get; set; } | ||
|
||
public string Prediction { get; set; } | ||
|
||
public DateTime DateTime { get; set; } | ||
|
||
public int UserId { get; set; } | ||
public User User { get; set; } | ||
|
||
public int GameId { get; set; } | ||
public Game Game { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
05.Entity Relations/BookmakerSystem/P03_FootballBetting/Data/Models/Color.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace P03_FootballBetting.Data.Models | ||
{ | ||
using System.Collections.Generic; | ||
|
||
public class Color | ||
{ | ||
public int ColorId { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public ICollection<Team> PrimaryKitTeams { get; set; } | ||
|
||
public ICollection<Team> SecondaryKitTeams { get; set; } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
05.Entity Relations/BookmakerSystem/P03_FootballBetting/Data/Models/Country.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace P03_FootballBetting.Data.Models | ||
{ | ||
using System.Collections.Generic; | ||
|
||
public class Country | ||
{ | ||
public int CountryId { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public ICollection<Town> Towns { get; set; } | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
05.Entity Relations/BookmakerSystem/P03_FootballBetting/Data/Models/Game.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace P03_FootballBetting.Data.Models | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
public class Game | ||
{ | ||
public int GameId { get; set; } | ||
|
||
public int HomeTeamId { get; set; } | ||
public Team HomeTeam { get; set; } | ||
|
||
public int AwayTeamId { get; set; } | ||
public Team AwayTeam { get; set; } | ||
|
||
public int HomeTeamGoals { get; set; } | ||
|
||
public int AwayTeamGoals { get; set; } | ||
|
||
public DateTime DateTime { get; set; } | ||
|
||
public decimal HomeTeamBetRate { get; set; } | ||
|
||
public decimal AwayTeamBetRate { get; set; } | ||
|
||
public decimal DrawBetRate { get; set; } | ||
|
||
public string Result { get; set; } | ||
|
||
public ICollection<PlayerStatistic> PlayerStatistics { get; set; } | ||
|
||
public ICollection<Bet> Bets { get; set; } | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
05.Entity Relations/BookmakerSystem/P03_FootballBetting/Data/Models/Player.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace P03_FootballBetting.Data.Models | ||
{ | ||
using System.Collections.Generic; | ||
|
||
public class Player | ||
{ | ||
public int PlayerId { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public int SquadNumber { get; set; } | ||
|
||
public bool IsInjured { get; set; } | ||
|
||
public int TeamId { get; set; } | ||
public Team Team { get; set; } | ||
|
||
public int PositionId { get; set; } | ||
public Position Position { get; set; } | ||
|
||
public ICollection<PlayerStatistic> PlayerStatistics { get; set; } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
05.Entity Relations/BookmakerSystem/P03_FootballBetting/Data/Models/PlayerStatistic.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace P03_FootballBetting.Data.Models | ||
{ | ||
public class PlayerStatistic | ||
{ | ||
public int GameId { get; set; } | ||
public Game Game { get; set; } | ||
|
||
public int PlayerId { get; set; } | ||
public Player Player { get; set; } | ||
|
||
public int ScoredGoals { get; set; } | ||
|
||
public int Assists { get; set; } | ||
|
||
public int MinutesPlayed { get; set; } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
05.Entity Relations/BookmakerSystem/P03_FootballBetting/Data/Models/Position.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace P03_FootballBetting.Data.Models | ||
{ | ||
using System.Collections.Generic; | ||
|
||
public class Position | ||
{ | ||
public int PositionId { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public ICollection<Player> Players { get; set; } | ||
} | ||
} |
Oops, something went wrong.