Commit 70eb14eb by dingsongjie

完成 backet 领域模型

parent 8ff3faf3
......@@ -9,6 +9,12 @@
<Compile Remove="Migrations\20200117082211_Init.Designer.cs" />
<Compile Remove="Migrations\20200117091659_Set_Backet_BacketItem_IsRequired_false.cs" />
<Compile Remove="Migrations\20200117091659_Set_Backet_BacketItem_IsRequired_false.Designer.cs" />
<Compile Remove="Migrations\20200119012712_Remove_BacketItem_FK_Constraint.cs" />
<Compile Remove="Migrations\20200119012712_Remove_BacketItem_FK_Constraint.Designer.cs" />
<Compile Remove="Migrations\20200119013717_Remove_BacketItem_FK_Constraint.cs" />
<Compile Remove="Migrations\20200119013717_Remove_BacketItem_FK_Constraint.Designer.cs" />
<Compile Remove="Migrations\20200119020005_Update_BacketItem_FK_Constraint.cs" />
<Compile Remove="Migrations\20200119020005_Update_BacketItem_FK_Constraint.Designer.cs" />
</ItemGroup>
<ItemGroup>
......
......@@ -9,7 +9,7 @@ namespace Backet.Api.Domain.AggregatesModel.BacketAggregate
public class Backet: Entity,IAggregateRoot
{
public string UserId { get; set; }
public IReadOnlyCollection<BacketItem> BacketItems { get; private set; }
public IEnumerable<BacketItem> BacketItems { get; private set; }
public long TotalPrice { get; set; }
}
}
......@@ -11,5 +11,6 @@ namespace Backet.Api.Domain.AggregatesModel.BacketAggregate
public string ProductId { get; set; }
public string ProductName { get; set; }
public long Price { get; set; }
public string BacketId { get; set; }
}
}
......@@ -15,7 +15,7 @@ namespace Backet.Api.Infrastructure.EntityConfigurations
builder.Property(m => m.Id).HasMaxLength(32);
builder.Property(m => m.UserId).HasMaxLength(32).IsRequired();
builder.HasMany(m => m.BacketItems).WithOne();
builder.HasMany(m => m.BacketItems).WithOne().IsRequired().OnDelete(DeleteBehavior.Cascade).HasForeignKey("BacketId");
builder.Ignore(m => m.DomainEvents);
......
......@@ -17,6 +17,7 @@ namespace Backet.Api.Infrastructure.EntityConfigurations
builder.Property(m => m.Id).HasMaxLength(32);
builder.Property(m => m.ProductId).HasMaxLength(32);
builder.Property(m => m.ProductName).HasMaxLength(256).IsRequired();
builder.Property(m => m.BacketId).HasMaxLength(32).IsRequired();
builder.Ignore(m => m.DomainEvents);
......
// <auto-generated />
using Backet.Api.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Backet.Api.Migrations
{
[DbContext(typeof(BacketDbContext))]
[Migration("20200119013821_Remove_BacketItem_FK_Constraint")]
partial class Remove_BacketItem_FK_Constraint
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "3.1.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("Backet.Api.Domain.AggregatesModel.BacketAggregate.Backet", b =>
{
b.Property<string>("Id")
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.Property<long>("TotalPrice")
.HasColumnType("bigint");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Backet");
});
modelBuilder.Entity("Backet.Api.Domain.AggregatesModel.BacketAggregate.BacketItem", b =>
{
b.Property<string>("Id")
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.Property<string>("BacketId")
.IsRequired()
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.Property<long>("Price")
.HasColumnType("bigint");
b.Property<string>("ProductId")
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("character varying(256)")
.HasMaxLength(256);
b.HasKey("Id");
b.HasIndex("BacketId");
b.HasIndex("ProductId");
b.ToTable("BacketItem");
});
modelBuilder.Entity("Backet.Api.Domain.AggregatesModel.BacketAggregate.BacketItem", b =>
{
b.HasOne("Backet.Api.Domain.AggregatesModel.BacketAggregate.Backet", null)
.WithMany("BacketItems")
.HasForeignKey("BacketId")
.OnDelete(DeleteBehavior.Restrict);
});
#pragma warning restore 612, 618
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
namespace Backet.Api.Migrations
{
public partial class Remove_BacketItem_FK_Constraint : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "BacketId",
table: "BacketItem",
maxLength: 32,
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(32)",
oldNullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "BacketId",
table: "BacketItem",
type: "character varying(32)",
nullable: true,
oldClrType: typeof(string),
oldMaxLength: 32);
}
}
}
// <auto-generated />
using Backet.Api.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Backet.Api.Migrations
{
[DbContext(typeof(BacketDbContext))]
[Migration("20200119020249_Update_BacketItem_FK_Constraint")]
partial class Update_BacketItem_FK_Constraint
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "3.1.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
modelBuilder.Entity("Backet.Api.Domain.AggregatesModel.BacketAggregate.Backet", b =>
{
b.Property<string>("Id")
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.Property<long>("TotalPrice")
.HasColumnType("bigint");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Backet");
});
modelBuilder.Entity("Backet.Api.Domain.AggregatesModel.BacketAggregate.BacketItem", b =>
{
b.Property<string>("Id")
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.Property<string>("BacketId")
.IsRequired()
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.Property<long>("Price")
.HasColumnType("bigint");
b.Property<string>("ProductId")
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("character varying(256)")
.HasMaxLength(256);
b.HasKey("Id");
b.HasIndex("BacketId");
b.HasIndex("ProductId");
b.ToTable("BacketItem");
});
modelBuilder.Entity("Backet.Api.Domain.AggregatesModel.BacketAggregate.BacketItem", b =>
{
b.HasOne("Backet.Api.Domain.AggregatesModel.BacketAggregate.Backet", null)
.WithMany("BacketItems")
.HasForeignKey("BacketId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
namespace Backet.Api.Migrations
{
public partial class Update_BacketItem_FK_Constraint : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_BacketItem_Backet_BacketId",
table: "BacketItem");
migrationBuilder.AddForeignKey(
name: "FK_BacketItem_Backet_BacketId",
table: "BacketItem",
column: "BacketId",
principalTable: "Backet",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_BacketItem_Backet_BacketId",
table: "BacketItem");
migrationBuilder.AddForeignKey(
name: "FK_BacketItem_Backet_BacketId",
table: "BacketItem",
column: "BacketId",
principalTable: "Backet",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
}
}
......@@ -46,7 +46,9 @@ namespace Backet.Api.Migrations
.HasMaxLength(32);
b.Property<string>("BacketId")
.HasColumnType("character varying(32)");
.IsRequired()
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.Property<long>("Price")
.HasColumnType("bigint");
......@@ -73,7 +75,9 @@ namespace Backet.Api.Migrations
{
b.HasOne("Backet.Api.Domain.AggregatesModel.BacketAggregate.Backet", null)
.WithMany("BacketItems")
.HasForeignKey("BacketId");
.HasForeignKey("BacketId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment