midoking

Untitled

Apr 30th, 2023
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.84 KB | None | 0 0
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3.  
  4. #nullable disable
  5.  
  6. namespace MVC_Project.Migrations
  7. {
  8.     /// <inheritdoc />
  9.     public partial class AddedOrderAndInvoiceEntities : Migration
  10.     {
  11.         /// <inheritdoc />
  12.         protected override void Up(MigrationBuilder migrationBuilder)
  13.         {
  14.             migrationBuilder.CreateTable(
  15.                 name: "Invoices",
  16.                 columns: table => new
  17.                 {
  18.                     Id = table.Column<int>(type: "int", nullable: false)
  19.                         .Annotation("SqlServer:Identity", "1, 1"),
  20.                     InvoiceNumber = table.Column<string>(type: "nvarchar(max)", nullable: false),
  21.                     OrderId = table.Column<int>(type: "int", nullable: true),
  22.                     TotalPaid = table.Column<decimal>(type: "money", nullable: false),
  23.                     Currency = table.Column<string>(type: "nvarchar(max)", nullable: false),
  24.                     AddedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
  25.                 },
  26.                 constraints: table =>
  27.                 {
  28.                     table.PrimaryKey("PK_Invoices", x => x.Id);
  29.                 });
  30.  
  31.             migrationBuilder.CreateTable(
  32.                 name: "Orders",
  33.                 columns: table => new
  34.                 {
  35.                     Id = table.Column<int>(type: "int", nullable: false)
  36.                         .Annotation("SqlServer:Identity", "1, 1"),
  37.                     CustomerId = table.Column<int>(type: "int", nullable: false),
  38.                     AddressId = table.Column<int>(type: "int", nullable: false),
  39.                     CartId = table.Column<int>(type: "int", nullable: false),
  40.                     OrderStatus = table.Column<int>(type: "int", nullable: true),
  41.                     TotalPaid = table.Column<double>(type: "float", nullable: false),
  42.                     PaymentMethod = table.Column<int>(type: "int", nullable: false),
  43.                     InvoiceId = table.Column<int>(type: "int", nullable: true)
  44.                 },
  45.                 constraints: table =>
  46.                 {
  47.                     table.PrimaryKey("PK_Orders", x => x.Id);
  48.                     table.ForeignKey(
  49.                         name: "FK_Orders_Accounts_CustomerId",
  50.                         column: x => x.CustomerId,
  51.                         principalTable: "Accounts",
  52.                         principalColumn: "Id",
  53.                         onDelete: ReferentialAction.Cascade);
  54.                     table.ForeignKey(
  55.                         name: "FK_Orders_Addresses_AddressId",
  56.                         column: x => x.AddressId,
  57.                         principalTable: "Addresses",
  58.                         principalColumn: "Id",
  59.                         onDelete: ReferentialAction.Cascade);
  60.                     table.ForeignKey(
  61.                         name: "FK_Orders_Carts_CartId",
  62.                         column: x => x.CartId,
  63.                         principalTable: "Carts",
  64.                         principalColumn: "Id",
  65.                         onDelete: ReferentialAction.Cascade);
  66.                     table.ForeignKey(
  67.                         name: "FK_Orders_Invoices_InvoiceId",
  68.                         column: x => x.InvoiceId,
  69.                         principalTable: "Invoices",
  70.                         principalColumn: "Id");
  71.                 });
  72.  
  73.             migrationBuilder.CreateIndex(
  74.                 name: "IX_Invoices_OrderId",
  75.                 table: "Invoices",
  76.                 column: "OrderId");
  77.  
  78.             migrationBuilder.CreateIndex(
  79.                 name: "IX_Orders_AddressId",
  80.                 table: "Orders",
  81.                 column: "AddressId");
  82.  
  83.             migrationBuilder.CreateIndex(
  84.                 name: "IX_Orders_CartId",
  85.                 table: "Orders",
  86.                 column: "CartId");
  87.  
  88.             migrationBuilder.CreateIndex(
  89.                 name: "IX_Orders_CustomerId",
  90.                 table: "Orders",
  91.                 column: "CustomerId");
  92.  
  93.             migrationBuilder.CreateIndex(
  94.                 name: "IX_Orders_InvoiceId",
  95.                 table: "Orders",
  96.                 column: "InvoiceId");
  97.  
  98.             migrationBuilder.AddForeignKey(
  99.                 name: "FK_Invoices_Orders_OrderId",
  100.                 table: "Invoices",
  101.                 column: "OrderId",
  102.                 principalTable: "Orders",
  103.                 principalColumn: "Id");
  104.         }
  105.  
  106.         /// <inheritdoc />
  107.         protected override void Down(MigrationBuilder migrationBuilder)
  108.         {
  109.             migrationBuilder.DropForeignKey(
  110.                 name: "FK_Invoices_Orders_OrderId",
  111.                 table: "Invoices");
  112.  
  113.             migrationBuilder.DropTable(
  114.                 name: "Orders");
  115.  
  116.             migrationBuilder.DropTable(
  117.                 name: "Invoices");
  118.         }
  119.     }
  120. }
  121.  
Advertisement
Add Comment
Please, Sign In to add comment