-
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
Showing
16 changed files
with
228 additions
and
29 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
@@ -1,23 +1,41 @@ | ||
using Npgsql.NameTranslation; | ||
using System.Data.Entity; | ||
#nullable enable | ||
|
||
#nullable enable | ||
using Npgsql.NameTranslation; | ||
|
||
namespace Snittlistan.Web.Infrastructure.Database; | ||
|
||
public class BitsContext : DbContext, IBitsContext | ||
{ | ||
public IDbSet<Bits_Team> Teams { get; set; } = null!; | ||
public BitsContext() | ||
{ | ||
Configuration.AutoDetectChangesEnabled = false; | ||
Configuration.LazyLoadingEnabled = false; | ||
} | ||
|
||
public IDbSet<Bits_Team> Team { get; set; } = null!; | ||
|
||
public IDbSet<Bits_Hall> Hall { get; set; } = null!; | ||
|
||
public IDbSet<Bits_Hall> Hallar { get; set; } = null!; | ||
public IDbSet<Bits_Match> Match { get; set; } = null!; | ||
|
||
public IDbSet<Bits_TeamRef> TeamRef { get; set; } = null!; | ||
|
||
public IDbSet<Bits_OilProfile> OilProfile { get; set; } = null!; | ||
|
||
protected override void OnModelCreating(DbModelBuilder modelBuilder) | ||
{ | ||
base.OnModelCreating(modelBuilder); | ||
System.Data.Entity.Database.SetInitializer(new NullDatabaseInitializer<BitsContext>()); | ||
NpgsqlSnakeCaseNameTranslator mapper = new(); | ||
_ = modelBuilder.HasDefaultSchema("bits"); | ||
modelBuilder.Properties().Configure(x => x.HasColumnName(mapper.TranslateMemberName(x.ClrPropertyInfo.Name))); | ||
modelBuilder.Types().Configure(x => x.ToTable(mapper.TranslateMemberName(x.ClrType.Name.Replace("Bits", string.Empty)))); | ||
modelBuilder.Properties().Configure(x => x.HasColumnName( | ||
mapper.TranslateMemberName(x.ClrPropertyInfo.Name))); | ||
modelBuilder.Types().Configure(x => x.ToTable( | ||
mapper.TranslateMemberName(x.ClrType.Name.Replace("Bits_", string.Empty)))); | ||
|
||
_ = modelBuilder.Entity<Bits_HallRef>() | ||
.HasOptional(x => x.Hall) | ||
.WithOptionalDependent(x => x!.HallRef) | ||
.Map(x => x.MapKey("hall_id")); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,19 @@ | ||
#nullable enable | ||
|
||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Snittlistan.Web.Infrastructure.Database; | ||
|
||
public class Bits_Hall | ||
{ | ||
public int ExternalHallId { get; set; } | ||
[Key] | ||
public int HallId { get; private set; } | ||
|
||
public int ExternalHallId { get; private set; } | ||
|
||
public string HallName { get; private set; } = string.Empty; | ||
|
||
public int HallRefId { get; set; } | ||
|
||
public string HallName { get; set; } = null!; | ||
public Bits_HallRef HallRef { get; private set; } = null!; | ||
} |
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 @@ | ||
#nullable enable | ||
|
||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace Snittlistan.Web.Infrastructure.Database; | ||
|
||
public class Bits_HallRef | ||
{ | ||
[Key] | ||
public int HallRefId { get; private set; } | ||
|
||
public int ExternalHallId { get; private set; } | ||
|
||
//[ForeignKey(nameof(Hall))] | ||
//public int HallId { get; private set; } | ||
|
||
public string HallName { get; private set; } = string.Empty; | ||
|
||
public Bits_Hall? Hall { get; private set; } | ||
} |
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 @@ | ||
#nullable enable | ||
|
||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace Snittlistan.Web.Infrastructure.Database; | ||
|
||
/* | ||
* SELECT | ||
m.external_match_id, | ||
tr_home.team_name AS home_team_name, | ||
tr_home.team_alias AS home_team_alias, | ||
tr_away.team_name AS away_team_name, | ||
tr_away.team_alias AS away_team_alias, | ||
op.oil_profile_name, | ||
hr.hall_name | ||
FROM | ||
bits.match m | ||
JOIN bits.team_ref tr_home ON m.match_home_team_ref_id = tr_home.team_ref_id | ||
JOIN bits.team_ref tr_away ON m.match_away_team_ref_id = tr_away.team_ref_id | ||
JOIN bits.oil_profile op ON m.match_oil_profile_id = op.oil_profile_id | ||
JOIN bits.hall_ref hr ON m.match_hall_ref_id = hr.hall_ref_id | ||
WHERE | ||
m.external_match_id = 3235829; | ||
*/ | ||
public class Bits_Match | ||
{ | ||
[Key] | ||
public int MatchId { get; private set; } | ||
|
||
public int ExternalMatchId { get; private set; } | ||
|
||
public DateTime MatchDateTime { get; private set; } | ||
|
||
[Column("match_home_team_ref_id")] | ||
[ForeignKey(nameof(HomeTeamRef))] | ||
public int HomeTeamRefId { get; private set; } | ||
|
||
public virtual Bits_TeamRef HomeTeamRef { get; private set; } = null!; | ||
|
||
[Column("match_away_team_ref_id")] | ||
[ForeignKey(nameof(AwayTeamRef))] | ||
public int AwayTeamRefId { get; private set; } | ||
|
||
public virtual Bits_TeamRef AwayTeamRef { get; private set; } = null!; | ||
|
||
[Column("match_oil_profile_id")] | ||
[ForeignKey(nameof(OilProfile))] | ||
public int OilProfileId { get; private set; } | ||
|
||
public virtual Bits_OilProfile OilProfile { get; private set; } = null!; | ||
|
||
[Column("match_hall_ref_id")] | ||
[ForeignKey(nameof(HallRef))] | ||
public int HallRefId { get; private set; } | ||
|
||
public Bits_HallRef HallRef { get; private set; } = null!; | ||
} |
16 changes: 16 additions & 0 deletions
16
Snittlistan.Web/Infrastructure/Database/Bits_OilProfile.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,16 @@ | ||
#nullable enable | ||
|
||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace Snittlistan.Web.Infrastructure.Database; | ||
|
||
public class Bits_OilProfile | ||
{ | ||
[Key] | ||
public int OilProfileId { get; set; } | ||
|
||
[InverseProperty(nameof(Bits_Match.OilProfile))] | ||
public virtual ICollection<Bits_Match> Matches { get; set; } = | ||
new HashSet<Bits_Match>(); | ||
} |
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
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,26 @@ | ||
#nullable enable | ||
|
||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace Snittlistan.Web.Infrastructure.Database; | ||
|
||
public class Bits_TeamRef | ||
{ | ||
[Key] | ||
public int TeamRefId { get; private set; } | ||
|
||
public int ExternalTeamId { get; set; } | ||
|
||
public string TeamName { get; private set; } = string.Empty; | ||
|
||
public string TeamAlias { get; set; } = string.Empty; | ||
|
||
[InverseProperty(nameof(Bits_Match.HomeTeamRef))] | ||
public virtual ICollection<Bits_Match> HomeMatches { get; private set; } = | ||
new HashSet<Bits_Match>(); | ||
|
||
[InverseProperty(nameof(Bits_Match.AwayTeamRef))] | ||
public virtual ICollection<Bits_Match> AwayMatches { get; private set; } = | ||
new HashSet<Bits_Match>(); | ||
} |
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 |
---|---|---|
@@ -1,12 +1,16 @@ | ||
| ||
using System.Data.Entity; | ||
|
||
#nullable enable | ||
#nullable enable | ||
|
||
namespace Snittlistan.Web.Infrastructure.Database; | ||
|
||
public interface IBitsContext | ||
{ | ||
public IDbSet<Bits_Team> Teams { get; } | ||
public IDbSet<Bits_Team> Team { get; } | ||
|
||
public IDbSet<Bits_Hall> Hall { get; } | ||
|
||
public IDbSet<Bits_Match> Match { get; } | ||
|
||
public IDbSet<Bits_TeamRef> TeamRef { get; } | ||
|
||
public IDbSet<Bits_Hall> Hallar { get; } | ||
public IDbSet<Bits_OilProfile> OilProfile { get; } | ||
} |
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
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
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
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
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