WebVenta/WebVentaCoche/Migrations/20241217132517_Orders-OrderDetails.cs
2024-12-17 14:57:49 +01:00

101 lines
4.0 KiB
C#

using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace WebVentaCoche.Migrations
{
/// <inheritdoc />
public partial class OrdersOrderDetails : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "OrderDetailViewModel");
migrationBuilder.CreateTable(
name: "OrderDetails",
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),
UnitPrice = table.Column<decimal>(type: "decimal(18,2)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_OrderDetails", x => x.Id);
table.ForeignKey(
name: "FK_OrderDetails_Orders_OrderId",
column: x => x.OrderId,
principalTable: "Orders",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_OrderDetails_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_OrderDetails_OrderId",
table: "OrderDetails",
column: "OrderId");
migrationBuilder.CreateIndex(
name: "IX_OrderDetails_ProductId",
table: "OrderDetails",
column: "ProductId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "OrderDetails");
migrationBuilder.CreateTable(
name: "OrderDetailViewModel",
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),
UnitPrice = table.Column<decimal>(type: "decimal(18,2)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_OrderDetailViewModel", x => x.Id);
table.ForeignKey(
name: "FK_OrderDetailViewModel_Orders_OrderId",
column: x => x.OrderId,
principalTable: "Orders",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_OrderDetailViewModel_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_OrderDetailViewModel_OrderId",
table: "OrderDetailViewModel",
column: "OrderId");
migrationBuilder.CreateIndex(
name: "IX_OrderDetailViewModel_ProductId",
table: "OrderDetailViewModel",
column: "ProductId");
}
}
}