relation test (collection)

This commit is contained in:
2023-08-28 13:30:53 +09:00
parent 1c98b870d8
commit d632b3abba
8 changed files with 437 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using WebAPI.Data;
#nullable disable
namespace WebAPI.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20230828042927_book-review")]
partial class bookreview
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("SharedData.Models.Book", b =>
{
b.Property<int>("BookId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("BookId"));
b.Property<string>("ISBN")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("BookId");
b.ToTable("Books");
});
modelBuilder.Entity("SharedData.Models.GameResult", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("datetime2");
b.Property<int>("Score")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.Property<string>("UserName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("GameResults");
});
modelBuilder.Entity("SharedData.Models.Review", b =>
{
b.Property<int>("ReviewId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ReviewId"));
b.Property<int?>("BookId")
.HasColumnType("int");
b.Property<string>("Context")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("ReviewId");
b.HasIndex("BookId");
b.ToTable("Reviews");
});
modelBuilder.Entity("SharedData.Models.Review", b =>
{
b.HasOne("SharedData.Models.Book", null)
.WithMany("Reviews")
.HasForeignKey("BookId");
});
modelBuilder.Entity("SharedData.Models.Book", b =>
{
b.Navigation("Reviews");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,62 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace WebAPI.Migrations
{
/// <inheritdoc />
public partial class bookreview : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Books",
columns: table => new
{
BookId = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Title = table.Column<string>(type: "nvarchar(max)", nullable: false),
ISBN = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Books", x => x.BookId);
});
migrationBuilder.CreateTable(
name: "Reviews",
columns: table => new
{
ReviewId = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Context = table.Column<string>(type: "nvarchar(max)", nullable: false),
BookId = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Reviews", x => x.ReviewId);
table.ForeignKey(
name: "FK_Reviews_Books_BookId",
column: x => x.BookId,
principalTable: "Books",
principalColumn: "BookId");
});
migrationBuilder.CreateIndex(
name: "IX_Reviews_BookId",
table: "Reviews",
column: "BookId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Reviews");
migrationBuilder.DropTable(
name: "Books");
}
}
}

View File

@@ -0,0 +1,113 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using WebAPI.Data;
#nullable disable
namespace WebAPI.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20230828043008_book-review2")]
partial class bookreview2
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("SharedData.Models.Book", b =>
{
b.Property<int>("BookId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("BookId"));
b.Property<string>("ISBN")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("BookId");
b.ToTable("Books");
});
modelBuilder.Entity("SharedData.Models.GameResult", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("datetime2");
b.Property<int>("Score")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.Property<string>("UserName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("GameResults");
});
modelBuilder.Entity("SharedData.Models.Review", b =>
{
b.Property<int>("ReviewId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ReviewId"));
b.Property<int>("BookId")
.HasColumnType("int");
b.Property<string>("Context")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("ReviewId");
b.HasIndex("BookId");
b.ToTable("Reviews");
});
modelBuilder.Entity("SharedData.Models.Review", b =>
{
b.HasOne("SharedData.Models.Book", null)
.WithMany("Reviews")
.HasForeignKey("BookId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("SharedData.Models.Book", b =>
{
b.Navigation("Reviews");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,59 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace WebAPI.Migrations
{
/// <inheritdoc />
public partial class bookreview2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Reviews_Books_BookId",
table: "Reviews");
migrationBuilder.AlterColumn<int>(
name: "BookId",
table: "Reviews",
type: "int",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AddForeignKey(
name: "FK_Reviews_Books_BookId",
table: "Reviews",
column: "BookId",
principalTable: "Books",
principalColumn: "BookId",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Reviews_Books_BookId",
table: "Reviews");
migrationBuilder.AlterColumn<int>(
name: "BookId",
table: "Reviews",
type: "int",
nullable: true,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AddForeignKey(
name: "FK_Reviews_Books_BookId",
table: "Reviews",
column: "BookId",
principalTable: "Books",
principalColumn: "BookId");
}
}
}

View File

@@ -22,6 +22,27 @@ namespace WebAPI.Migrations
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("SharedData.Models.Book", b =>
{
b.Property<int>("BookId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("BookId"));
b.Property<string>("ISBN")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("BookId");
b.ToTable("Books");
});
modelBuilder.Entity("SharedData.Models.GameResult", b =>
{
b.Property<int>("Id")
@@ -47,6 +68,42 @@ namespace WebAPI.Migrations
b.ToTable("GameResults");
});
modelBuilder.Entity("SharedData.Models.Review", b =>
{
b.Property<int>("ReviewId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ReviewId"));
b.Property<int>("BookId")
.HasColumnType("int");
b.Property<string>("Context")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("ReviewId");
b.HasIndex("BookId");
b.ToTable("Reviews");
});
modelBuilder.Entity("SharedData.Models.Review", b =>
{
b.HasOne("SharedData.Models.Book", null)
.WithMany("Reviews")
.HasForeignKey("BookId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("SharedData.Models.Book", b =>
{
b.Navigation("Reviews");
});
#pragma warning restore 612, 618
}
}