60 lines
2.2 KiB
C#
60 lines
2.2 KiB
C#
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace DEMO.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddOrderItems : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "OrderItems",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("SqlServer:Identity", "1, 1"),
|
|
OrderId = table.Column<int>(type: "int", nullable: false),
|
|
ProductId = table.Column<int>(type: "int", nullable: false),
|
|
Quantity = table.Column<int>(type: "int", nullable: false),
|
|
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_OrderItems", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_OrderItems_Orders_OrderId",
|
|
column: x => x.OrderId,
|
|
principalTable: "Orders",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_OrderItems_Products_ProductId",
|
|
column: x => x.ProductId,
|
|
principalTable: "Products",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_OrderItems_OrderId",
|
|
table: "OrderItems",
|
|
column: "OrderId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_OrderItems_ProductId",
|
|
table: "OrderItems",
|
|
column: "ProductId");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "OrderItems");
|
|
}
|
|
}
|
|
}
|