generated from admin/template
168 lines
6.4 KiB
C#
168 lines
6.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace PokedexApp.Models;
|
|
|
|
public partial class PokedexDbContext : DbContext
|
|
{
|
|
public PokedexDbContext()
|
|
{
|
|
}
|
|
|
|
public PokedexDbContext(DbContextOptions<PokedexDbContext> options)
|
|
: base(options)
|
|
{
|
|
}
|
|
|
|
public virtual DbSet<Ability> Abilities { get; set; }
|
|
|
|
public virtual DbSet<CaughtPokemon> CaughtPokemons { get; set; }
|
|
|
|
public virtual DbSet<Evolution> Evolutions { get; set; }
|
|
|
|
public virtual DbSet<Move> Moves { get; set; }
|
|
|
|
public virtual DbSet<Pokemon> Pokemons { get; set; }
|
|
|
|
public virtual DbSet<PokemonAbility> PokemonAbilities { get; set; }
|
|
|
|
public virtual DbSet<PokemonMove> PokemonMoves { get; set; }
|
|
|
|
public virtual DbSet<PokemonType> PokemonTypes { get; set; }
|
|
|
|
public virtual DbSet<Region> Regions { get; set; }
|
|
|
|
public virtual DbSet<Trainer> Trainers { get; set; }
|
|
|
|
public virtual DbSet<Type> Types { get; set; }
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
|
|
=> optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=pokedex_pass;");
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.Entity<Ability>(entity =>
|
|
{
|
|
entity.HasKey(e => e.AbilityId).HasName("ability_pkey");
|
|
|
|
entity.Property(e => e.AbilityId).UseIdentityAlwaysColumn();
|
|
});
|
|
|
|
modelBuilder.Entity<CaughtPokemon>(entity =>
|
|
{
|
|
entity.HasKey(e => e.CaughtPokemonId).HasName("caught_pokemon_pkey");
|
|
|
|
entity.Property(e => e.CaughtPokemonId).UseIdentityAlwaysColumn();
|
|
entity.Property(e => e.CaughtPokemonCatchDate).HasDefaultValueSql("CURRENT_DATE");
|
|
|
|
entity.HasOne(d => d.CatchRegion).WithMany(p => p.CaughtPokemons)
|
|
.OnDelete(DeleteBehavior.SetNull)
|
|
.HasConstraintName("caught_pokemon_catch_region_id_fkey");
|
|
|
|
entity.HasOne(d => d.Pokemon).WithMany(p => p.CaughtPokemons)
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
.HasConstraintName("caught_pokemon_pokemon_id_fkey");
|
|
|
|
entity.HasOne(d => d.Trainer).WithMany(p => p.CaughtPokemons).HasConstraintName("caught_pokemon_trainer_id_fkey");
|
|
});
|
|
|
|
modelBuilder.Entity<Evolution>(entity =>
|
|
{
|
|
entity.HasKey(e => e.EvolutionId).HasName("evolution_pkey");
|
|
|
|
entity.Property(e => e.EvolutionId).UseIdentityAlwaysColumn();
|
|
|
|
entity.HasOne(d => d.FromPokemon).WithMany(p => p.EvolutionFromPokemons).HasConstraintName("evolution_from_pokemon_id_fkey");
|
|
|
|
entity.HasOne(d => d.ToPokemon).WithMany(p => p.EvolutionToPokemons).HasConstraintName("evolution_to_pokemon_id_fkey");
|
|
});
|
|
|
|
modelBuilder.Entity<Move>(entity =>
|
|
{
|
|
entity.HasKey(e => e.MoveId).HasName("move_pkey");
|
|
|
|
entity.Property(e => e.MoveId).UseIdentityAlwaysColumn();
|
|
|
|
entity.HasOne(d => d.Type).WithMany(p => p.Moves)
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
.HasConstraintName("move_type_id_fkey");
|
|
});
|
|
|
|
modelBuilder.Entity<Pokemon>(entity =>
|
|
{
|
|
entity.HasKey(e => e.PokemonId).HasName("pokemon_pkey");
|
|
|
|
entity.Property(e => e.PokemonId).UseIdentityAlwaysColumn();
|
|
entity.Property(e => e.PokemonCreatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP");
|
|
|
|
entity.HasOne(d => d.Region).WithMany(p => p.Pokemons)
|
|
.OnDelete(DeleteBehavior.SetNull)
|
|
.HasConstraintName("pokemon_region_id_fkey");
|
|
});
|
|
|
|
modelBuilder.Entity<PokemonAbility>(entity =>
|
|
{
|
|
entity.HasKey(e => new { e.PokemonId, e.AbilityId }).HasName("pokemon_ability_pkey");
|
|
|
|
entity.HasOne(d => d.Ability).WithMany(p => p.PokemonAbilities)
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
.HasConstraintName("pokemon_ability_ability_id_fkey");
|
|
|
|
entity.HasOne(d => d.Pokemon).WithMany(p => p.PokemonAbilities).HasConstraintName("pokemon_ability_pokemon_id_fkey");
|
|
});
|
|
|
|
modelBuilder.Entity<PokemonMove>(entity =>
|
|
{
|
|
entity.HasKey(e => new { e.PokemonId, e.MoveId, e.PokemonMoveLearnMethod }).HasName("pokemon_move_pkey");
|
|
|
|
entity.HasOne(d => d.Move).WithMany(p => p.PokemonMoves).HasConstraintName("pokemon_move_move_id_fkey");
|
|
|
|
entity.HasOne(d => d.Pokemon).WithMany(p => p.PokemonMoves).HasConstraintName("pokemon_move_pokemon_id_fkey");
|
|
});
|
|
|
|
modelBuilder.Entity<PokemonType>(entity =>
|
|
{
|
|
entity.HasKey(e => new { e.PokemonId, e.TypeId }).HasName("pokemon_type_pkey");
|
|
|
|
entity.HasOne(d => d.Pokemon).WithMany(p => p.PokemonTypes).HasConstraintName("pokemon_type_pokemon_id_fkey");
|
|
|
|
entity.HasOne(d => d.Type).WithMany(p => p.PokemonTypes)
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
.HasConstraintName("pokemon_type_type_id_fkey");
|
|
});
|
|
|
|
modelBuilder.Entity<Region>(entity =>
|
|
{
|
|
entity.HasKey(e => e.RegionId).HasName("region_pkey");
|
|
|
|
entity.Property(e => e.RegionId).UseIdentityAlwaysColumn();
|
|
});
|
|
|
|
modelBuilder.Entity<Trainer>(entity =>
|
|
{
|
|
entity.HasKey(e => e.TrainerId).HasName("trainer_pkey");
|
|
|
|
entity.Property(e => e.TrainerId).UseIdentityAlwaysColumn();
|
|
entity.Property(e => e.TrainerRegisteredAt).HasDefaultValueSql("CURRENT_TIMESTAMP");
|
|
|
|
entity.HasOne(d => d.HomeRegion).WithMany(p => p.Trainers)
|
|
.OnDelete(DeleteBehavior.SetNull)
|
|
.HasConstraintName("trainer_home_region_id_fkey");
|
|
});
|
|
|
|
modelBuilder.Entity<Type>(entity =>
|
|
{
|
|
entity.HasKey(e => e.TypeId).HasName("type_pkey");
|
|
|
|
entity.Property(e => e.TypeId).UseIdentityAlwaysColumn();
|
|
entity.Property(e => e.TypeColorHex).IsFixedLength();
|
|
});
|
|
|
|
OnModelCreatingPartial(modelBuilder);
|
|
}
|
|
|
|
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
|
}
|