model revision

main
Peace 11 months ago
parent e004b313b6
commit bc70282e6e
  1. 123
      WebAPIWithEF/Migrations/20240611080745_ModelRevisions.Designer.cs
  2. 162
      WebAPIWithEF/Migrations/20240611080745_ModelRevisions.cs
  3. 59
      WebAPIWithEF/Migrations/PizzaContextModelSnapshot.cs
  4. 9
      WebAPIWithEF/Models/Pizza.cs
  5. 9
      WebAPIWithEF/Models/Sauce.cs
  6. 13
      WebAPIWithEF/Models/Topping.cs

@ -0,0 +1,123 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using WebAPIWithEF.Data;
#nullable disable
namespace WebAPIWithEF.Migrations
{
[DbContext(typeof(PizzaContext))]
[Migration("20240611080745_ModelRevisions")]
partial class ModelRevisions
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
modelBuilder.Entity("PizzaTopping", b =>
{
b.Property<int>("PizzasId")
.HasColumnType("INTEGER");
b.Property<int>("ToppingsId")
.HasColumnType("INTEGER");
b.HasKey("PizzasId", "ToppingsId");
b.HasIndex("ToppingsId");
b.ToTable("PizzaTopping");
});
modelBuilder.Entity("WebAPIWithEF.Models.Pizza", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<int?>("SauceId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("SauceId");
b.ToTable("Pizzas");
});
modelBuilder.Entity("WebAPIWithEF.Models.Sauce", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<bool>("IsVegan")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Sauces");
});
modelBuilder.Entity("WebAPIWithEF.Models.Topping", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<decimal>("Calories")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Toppings");
});
modelBuilder.Entity("PizzaTopping", b =>
{
b.HasOne("WebAPIWithEF.Models.Pizza", null)
.WithMany()
.HasForeignKey("PizzasId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("WebAPIWithEF.Models.Topping", null)
.WithMany()
.HasForeignKey("ToppingsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("WebAPIWithEF.Models.Pizza", b =>
{
b.HasOne("WebAPIWithEF.Models.Sauce", "Sauce")
.WithMany()
.HasForeignKey("SauceId");
b.Navigation("Sauce");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,162 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace WebAPIWithEF.Migrations
{
/// <inheritdoc />
public partial class ModelRevisions : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Toppings_Pizzas_PizzaId",
table: "Toppings");
migrationBuilder.DropIndex(
name: "IX_Toppings_PizzaId",
table: "Toppings");
migrationBuilder.DropColumn(
name: "PizzaId",
table: "Toppings");
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "Toppings",
type: "TEXT",
maxLength: 100,
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "TEXT",
oldNullable: true);
migrationBuilder.AddColumn<decimal>(
name: "Calories",
table: "Toppings",
type: "TEXT",
nullable: false,
defaultValue: 0m);
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "Sauces",
type: "TEXT",
maxLength: 100,
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "TEXT",
oldNullable: true);
migrationBuilder.AddColumn<bool>(
name: "IsVegan",
table: "Sauces",
type: "INTEGER",
nullable: false,
defaultValue: false);
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "Pizzas",
type: "TEXT",
maxLength: 100,
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "TEXT",
oldNullable: true);
migrationBuilder.CreateTable(
name: "PizzaTopping",
columns: table => new
{
PizzasId = table.Column<int>(type: "INTEGER", nullable: false),
ToppingsId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PizzaTopping", x => new { x.PizzasId, x.ToppingsId });
table.ForeignKey(
name: "FK_PizzaTopping_Pizzas_PizzasId",
column: x => x.PizzasId,
principalTable: "Pizzas",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PizzaTopping_Toppings_ToppingsId",
column: x => x.ToppingsId,
principalTable: "Toppings",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_PizzaTopping_ToppingsId",
table: "PizzaTopping",
column: "ToppingsId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PizzaTopping");
migrationBuilder.DropColumn(
name: "Calories",
table: "Toppings");
migrationBuilder.DropColumn(
name: "IsVegan",
table: "Sauces");
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "Toppings",
type: "TEXT",
nullable: true,
oldClrType: typeof(string),
oldType: "TEXT",
oldMaxLength: 100);
migrationBuilder.AddColumn<int>(
name: "PizzaId",
table: "Toppings",
type: "INTEGER",
nullable: true);
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "Sauces",
type: "TEXT",
nullable: true,
oldClrType: typeof(string),
oldType: "TEXT",
oldMaxLength: 100);
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "Pizzas",
type: "TEXT",
nullable: true,
oldClrType: typeof(string),
oldType: "TEXT",
oldMaxLength: 100);
migrationBuilder.CreateIndex(
name: "IX_Toppings_PizzaId",
table: "Toppings",
column: "PizzaId");
migrationBuilder.AddForeignKey(
name: "FK_Toppings_Pizzas_PizzaId",
table: "Toppings",
column: "PizzaId",
principalTable: "Pizzas",
principalColumn: "Id");
}
}
}

@ -17,6 +17,21 @@ namespace WebAPIWithEF.Migrations
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
modelBuilder.Entity("PizzaTopping", b =>
{
b.Property<int>("PizzasId")
.HasColumnType("INTEGER");
b.Property<int>("ToppingsId")
.HasColumnType("INTEGER");
b.HasKey("PizzasId", "ToppingsId");
b.HasIndex("ToppingsId");
b.ToTable("PizzaTopping");
});
modelBuilder.Entity("WebAPIWithEF.Models.Pizza", b =>
{
b.Property<int>("Id")
@ -24,6 +39,8 @@ namespace WebAPIWithEF.Migrations
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<int?>("SauceId")
@ -42,7 +59,12 @@ namespace WebAPIWithEF.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<bool>("IsVegan")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.HasKey("Id");
@ -56,38 +78,41 @@ namespace WebAPIWithEF.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
b.Property<decimal>("Calories")
.HasColumnType("TEXT");
b.Property<int?>("PizzaId")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("PizzaId");
b.ToTable("Toppings");
});
modelBuilder.Entity("WebAPIWithEF.Models.Pizza", b =>
modelBuilder.Entity("PizzaTopping", b =>
{
b.HasOne("WebAPIWithEF.Models.Sauce", "Sauce")
b.HasOne("WebAPIWithEF.Models.Pizza", null)
.WithMany()
.HasForeignKey("SauceId");
.HasForeignKey("PizzasId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Sauce");
});
modelBuilder.Entity("WebAPIWithEF.Models.Topping", b =>
{
b.HasOne("WebAPIWithEF.Models.Pizza", null)
.WithMany("Toppings")
.HasForeignKey("PizzaId");
b.HasOne("WebAPIWithEF.Models.Topping", null)
.WithMany()
.HasForeignKey("ToppingsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("WebAPIWithEF.Models.Pizza", b =>
{
b.Navigation("Toppings");
b.HasOne("WebAPIWithEF.Models.Sauce", "Sauce")
.WithMany()
.HasForeignKey("SauceId");
b.Navigation("Sauce");
});
#pragma warning restore 612, 618
}

@ -1,10 +1,17 @@
namespace WebAPIWithEF.Models
using System.ComponentModel.DataAnnotations;
namespace WebAPIWithEF.Models
{
public class Pizza
{
public int Id { get; set; }
[Required]
[MaxLength(100)]
public string? Name { get; set; }
public Sauce? Sauce { get; set; }
public ICollection<Topping>? Toppings { get; set; }
}
}

@ -1,8 +1,15 @@
namespace WebAPIWithEF.Models
using System.ComponentModel.DataAnnotations;
namespace WebAPIWithEF.Models
{
public class Sauce
{
public int Id { get; set; }
[Required]
[MaxLength(100)]
public string? Name { get; set; }
public bool IsVegan { get; set; }
}
}

@ -1,8 +1,19 @@
namespace WebAPIWithEF.Models
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
namespace WebAPIWithEF.Models
{
public class Topping
{
public int Id { get; set; }
[Required]
[MaxLength(100)]
public string? Name { get; set; }
public decimal Calories { get; set; }
[JsonIgnore]
public ICollection<Pizza>? Pizzas { get; set; }
}
}

Loading…
Cancel
Save