generated from admin/template
начал
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PokedexApi.Data.Models;
|
||||
[Table("ability")]
|
||||
[Index(nameof(Name), IsUnique = true)]
|
||||
public class Ability
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
[Column("ability_id")]
|
||||
public int AbilityId { get; set; }
|
||||
[Column("ability_name")]
|
||||
[Required]
|
||||
[MaxLength(100)]
|
||||
public string Name { get; set; }
|
||||
[Column("ability_description")]
|
||||
[Required]
|
||||
public string Description { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PokedexApi.Data.Models;
|
||||
[Table("pokemon")]
|
||||
[Index(nameof(Name), IsUnique = true)]
|
||||
public class Pokemon
|
||||
{
|
||||
[Key]
|
||||
[Column("pokemon_id")]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||
public int Id { get; set; }
|
||||
[Column("pokemon_name")]
|
||||
[Required]
|
||||
[MaxLength(30)]
|
||||
public string Name { get; set; }
|
||||
[Column("pokemon_height_m")]
|
||||
[Required]
|
||||
public double Height { get; set; }
|
||||
[Column("pokemon_weight_kg")]
|
||||
[Required]
|
||||
public double Weight { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PokedexApi.Data.Models;
|
||||
[Table("pokemonAbility")]
|
||||
[Index(nameof(Name), IsUnique = true)]
|
||||
public class PokemonAbility
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
[Column("pokemon_ability_id")]
|
||||
public int AbilityId { get; set; }
|
||||
[Column("pokemon_ability_name")]
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
[Column("IsHidden")]
|
||||
[Required]
|
||||
public bool IsHidden { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PokedexApi.Data.Models;
|
||||
[Table("type")]
|
||||
[Index(nameof(Name), IsUnique = true)]
|
||||
public class Type
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
[Column("type_id")]
|
||||
public int TypeId { get; set; }
|
||||
[Column("type_name")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PokedexApi.Data.Models;
|
||||
using Type = PokedexApi.Data.Models.Type;
|
||||
|
||||
namespace PokedexApi.Data;
|
||||
|
||||
public class PokemonContext: DbContext
|
||||
{
|
||||
public DbSet<Type> Types { get; set; }
|
||||
public DbSet<Pokemon> Pokemons { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
optionsBuilder.UseNpgsql("Username=postgres;Password=123;Host=localhost:5432;Database=postgres");
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
// <auto-generated />
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using PokedexApi.Data;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PokedexApi.Migrations
|
||||
{
|
||||
[DbContext(typeof(PokemonContext))]
|
||||
[Migration("20260911140633_Init")]
|
||||
partial class Init
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("PokedexApi.Data.Models.Type", b =>
|
||||
{
|
||||
b.Property<int>("TypeId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("type_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("TypeId"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("type_name");
|
||||
|
||||
b.HasKey("TypeId");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("type");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PokedexApi.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Init : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "type",
|
||||
columns: table => new
|
||||
{
|
||||
type_id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
type_name = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_type", x => x.type_id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_type_type_name",
|
||||
table: "type",
|
||||
column: "type_name",
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "type");
|
||||
}
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
// <auto-generated />
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using PokedexApi.Data;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PokedexApi.Migrations
|
||||
{
|
||||
[DbContext(typeof(PokemonContext))]
|
||||
[Migration("20260911142245_PokemonTable")]
|
||||
partial class PokemonTable
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("PokedexApi.Data.Models.Pokemon", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("pokemon_id");
|
||||
|
||||
b.Property<double>("Height")
|
||||
.HasColumnType("double precision")
|
||||
.HasColumnName("pokemon_height_m");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(30)
|
||||
.HasColumnType("character varying(30)")
|
||||
.HasColumnName("pokemon_name");
|
||||
|
||||
b.Property<double>("Weight")
|
||||
.HasColumnType("double precision")
|
||||
.HasColumnName("pokemon_weight_kg");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("pokemon");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PokedexApi.Data.Models.Type", b =>
|
||||
{
|
||||
b.Property<int>("TypeId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("type_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("TypeId"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("type_name");
|
||||
|
||||
b.HasKey("TypeId");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("type");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PokedexApi.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class PokemonTable : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "pokemon",
|
||||
columns: table => new
|
||||
{
|
||||
pokemon_id = table.Column<int>(type: "integer", nullable: false),
|
||||
pokemon_name = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),
|
||||
pokemon_height_m = table.Column<double>(type: "double precision", nullable: false),
|
||||
pokemon_weight_kg = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_pokemon", x => x.pokemon_id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_pokemon_pokemon_name",
|
||||
table: "pokemon",
|
||||
column: "pokemon_name",
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "pokemon");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// <auto-generated />
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using PokedexApi.Data;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PokedexApi.Migrations
|
||||
{
|
||||
[DbContext(typeof(PokemonContext))]
|
||||
partial class PokemonContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("PokedexApi.Data.Models.Pokemon", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("pokemon_id");
|
||||
|
||||
b.Property<double>("Height")
|
||||
.HasColumnType("double precision")
|
||||
.HasColumnName("pokemon_height_m");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(30)
|
||||
.HasColumnType("character varying(30)")
|
||||
.HasColumnName("pokemon_name");
|
||||
|
||||
b.Property<double>("Weight")
|
||||
.HasColumnType("double precision")
|
||||
.HasColumnName("pokemon_weight_kg");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("pokemon");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PokedexApi.Data.Models.Type", b =>
|
||||
{
|
||||
b.Property<int>("TypeId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("type_id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("TypeId"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("type_name");
|
||||
|
||||
b.HasKey("TypeId");
|
||||
|
||||
b.HasIndex("Name")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("type");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,7 @@
|
||||
using PokedexApi.Data;
|
||||
|
||||
PokemonContext pk = new PokemonContext();
|
||||
Console.WriteLine(
|
||||
string.Join(", ",
|
||||
pk.Pokemons.Select(pk => pk.Name)
|
||||
));
|
||||
Reference in New Issue
Block a user