@ -0,0 +1,227 @@ | |||
using System; | |||
using Microsoft.EntityFrameworkCore; | |||
using Microsoft.EntityFrameworkCore.Infrastructure; | |||
using Microsoft.EntityFrameworkCore.Metadata; | |||
using Microsoft.EntityFrameworkCore.Migrations; | |||
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure; | |||
namespace Ordering.API.Infrastructure.Migrations | |||
{ | |||
[DbContext(typeof(OrderingContext))] | |||
[Migration("20161122162602_initial")] | |||
partial class initial | |||
{ | |||
protected override void BuildTargetModel(ModelBuilder modelBuilder) | |||
{ | |||
modelBuilder | |||
.HasAnnotation("ProductVersion", "1.0.1") | |||
.HasAnnotation("SqlServer:Sequence:ordering.buyerseq", "'buyerseq', 'ordering', '1', '10', '', '', 'Int64', 'False'") | |||
.HasAnnotation("SqlServer:Sequence:ordering.orderseq", "'orderseq', 'ordering', '1', '10', '', '', 'Int64', 'False'") | |||
.HasAnnotation("SqlServer:Sequence:ordering.paymentseq", "'paymentseq', 'ordering', '1', '10', '', '', 'Int64', 'False'") | |||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", b => | |||
{ | |||
b.Property<int>("Id") | |||
.ValueGeneratedOnAdd(); | |||
b.Property<string>("City"); | |||
b.Property<string>("Country"); | |||
b.Property<string>("CountryCode"); | |||
b.Property<double>("Latitude"); | |||
b.Property<double>("Longitude"); | |||
b.Property<string>("State"); | |||
b.Property<string>("StateCode"); | |||
b.Property<string>("Street"); | |||
b.Property<string>("ZipCode"); | |||
b.HasKey("Id"); | |||
b.ToTable("address","ordering"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer", b => | |||
{ | |||
b.Property<int>("Id") | |||
.ValueGeneratedOnAdd() | |||
.HasAnnotation("SqlServer:HiLoSequenceName", "buyerseq") | |||
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") | |||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); | |||
b.Property<string>("FullName") | |||
.IsRequired() | |||
.HasAnnotation("MaxLength", 200); | |||
b.HasKey("Id"); | |||
b.ToTable("buyers","ordering"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.CardType", b => | |||
{ | |||
b.Property<int>("Id") | |||
.ValueGeneratedOnAdd(); | |||
b.Property<string>("Name"); | |||
b.HasKey("Id"); | |||
b.ToTable("cardtypes","ordering"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order", b => | |||
{ | |||
b.Property<int>("Id") | |||
.ValueGeneratedOnAdd() | |||
.HasAnnotation("SqlServer:HiLoSequenceName", "orderseq") | |||
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") | |||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); | |||
b.Property<int?>("BillingAddressId"); | |||
b.Property<int>("BuyerId"); | |||
b.Property<DateTime>("OrderDate"); | |||
b.Property<int>("PaymentId"); | |||
b.Property<int?>("ShippingAddressId"); | |||
b.Property<int>("StatusId"); | |||
b.HasKey("Id"); | |||
b.HasIndex("BillingAddressId"); | |||
b.HasIndex("BuyerId"); | |||
b.HasIndex("PaymentId"); | |||
b.HasIndex("ShippingAddressId"); | |||
b.HasIndex("StatusId"); | |||
b.ToTable("orders","ordering"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderItem", b => | |||
{ | |||
b.Property<int>("Id") | |||
.ValueGeneratedOnAdd(); | |||
b.Property<decimal>("Discount"); | |||
b.Property<int>("OrderId"); | |||
b.Property<int>("ProductId"); | |||
b.Property<string>("ProductName") | |||
.IsRequired(); | |||
b.Property<decimal>("UnitPrice"); | |||
b.Property<int>("Units") | |||
.ValueGeneratedOnAdd() | |||
.HasAnnotation("SqlServer:DefaultValue", 1); | |||
b.HasKey("Id"); | |||
b.HasIndex("OrderId"); | |||
b.ToTable("orderItems","ordering"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderStatus", b => | |||
{ | |||
b.Property<int>("Id") | |||
.ValueGeneratedOnAdd(); | |||
b.Property<string>("Name"); | |||
b.HasKey("Id"); | |||
b.ToTable("orderstatus","ordering"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", b => | |||
{ | |||
b.Property<int>("Id") | |||
.ValueGeneratedOnAdd() | |||
.HasAnnotation("SqlServer:HiLoSequenceName", "paymentseq") | |||
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") | |||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); | |||
b.Property<string>("CardHolderName") | |||
.IsRequired() | |||
.HasAnnotation("MaxLength", 200); | |||
b.Property<string>("CardNumber") | |||
.IsRequired() | |||
.HasAnnotation("MaxLength", 25); | |||
b.Property<int>("CardTypeId"); | |||
b.Property<DateTime>("Expiration"); | |||
b.Property<string>("SecurityNumber"); | |||
b.HasKey("Id"); | |||
b.HasIndex("CardTypeId"); | |||
b.ToTable("payments","ordering"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order", b => | |||
{ | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", "BillingAddress") | |||
.WithMany() | |||
.HasForeignKey("BillingAddressId") | |||
.OnDelete(DeleteBehavior.SetNull); | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer", "Buyer") | |||
.WithMany() | |||
.HasForeignKey("BuyerId") | |||
.OnDelete(DeleteBehavior.Cascade); | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", "Payment") | |||
.WithMany() | |||
.HasForeignKey("PaymentId") | |||
.OnDelete(DeleteBehavior.Cascade); | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", "ShippingAddress") | |||
.WithMany() | |||
.HasForeignKey("ShippingAddressId"); | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderStatus", "Status") | |||
.WithMany() | |||
.HasForeignKey("StatusId") | |||
.OnDelete(DeleteBehavior.Cascade); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderItem", b => | |||
{ | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order") | |||
.WithMany("OrderItems") | |||
.HasForeignKey("OrderId") | |||
.OnDelete(DeleteBehavior.Cascade); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", b => | |||
{ | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.CardType", "CardType") | |||
.WithMany() | |||
.HasForeignKey("CardTypeId") | |||
.OnDelete(DeleteBehavior.Cascade); | |||
}); | |||
} | |||
} | |||
} |
@ -0,0 +1,282 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using Microsoft.EntityFrameworkCore.Migrations; | |||
using Microsoft.EntityFrameworkCore.Metadata; | |||
namespace Ordering.API.Infrastructure.Migrations | |||
{ | |||
public partial class initial : Migration | |||
{ | |||
protected override void Up(MigrationBuilder migrationBuilder) | |||
{ | |||
migrationBuilder.EnsureSchema( | |||
name: "ordering"); | |||
migrationBuilder.CreateSequence( | |||
name: "buyerseq", | |||
schema: "ordering", | |||
incrementBy: 10); | |||
migrationBuilder.CreateSequence( | |||
name: "orderseq", | |||
schema: "ordering", | |||
incrementBy: 10); | |||
migrationBuilder.CreateSequence( | |||
name: "paymentseq", | |||
schema: "ordering", | |||
incrementBy: 10); | |||
migrationBuilder.CreateTable( | |||
name: "address", | |||
schema: "ordering", | |||
columns: table => new | |||
{ | |||
Id = table.Column<int>(nullable: false) | |||
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), | |||
City = table.Column<string>(nullable: true), | |||
Country = table.Column<string>(nullable: true), | |||
CountryCode = table.Column<string>(nullable: true), | |||
Latitude = table.Column<double>(nullable: false), | |||
Longitude = table.Column<double>(nullable: false), | |||
State = table.Column<string>(nullable: true), | |||
StateCode = table.Column<string>(nullable: true), | |||
Street = table.Column<string>(nullable: true), | |||
ZipCode = table.Column<string>(nullable: true) | |||
}, | |||
constraints: table => | |||
{ | |||
table.PrimaryKey("PK_address", x => x.Id); | |||
}); | |||
migrationBuilder.CreateTable( | |||
name: "buyers", | |||
schema: "ordering", | |||
columns: table => new | |||
{ | |||
Id = table.Column<int>(nullable: false), | |||
FullName = table.Column<string>(maxLength: 200, nullable: false) | |||
}, | |||
constraints: table => | |||
{ | |||
table.PrimaryKey("PK_buyers", x => x.Id); | |||
}); | |||
migrationBuilder.CreateTable( | |||
name: "cardtypes", | |||
schema: "ordering", | |||
columns: table => new | |||
{ | |||
Id = table.Column<int>(nullable: false) | |||
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), | |||
Name = table.Column<string>(nullable: true) | |||
}, | |||
constraints: table => | |||
{ | |||
table.PrimaryKey("PK_cardtypes", x => x.Id); | |||
}); | |||
migrationBuilder.CreateTable( | |||
name: "orderstatus", | |||
schema: "ordering", | |||
columns: table => new | |||
{ | |||
Id = table.Column<int>(nullable: false) | |||
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), | |||
Name = table.Column<string>(nullable: true) | |||
}, | |||
constraints: table => | |||
{ | |||
table.PrimaryKey("PK_orderstatus", x => x.Id); | |||
}); | |||
migrationBuilder.CreateTable( | |||
name: "payments", | |||
schema: "ordering", | |||
columns: table => new | |||
{ | |||
Id = table.Column<int>(nullable: false), | |||
CardHolderName = table.Column<string>(maxLength: 200, nullable: false), | |||
CardNumber = table.Column<string>(maxLength: 25, nullable: false), | |||
CardTypeId = table.Column<int>(nullable: false), | |||
Expiration = table.Column<DateTime>(nullable: false), | |||
SecurityNumber = table.Column<string>(nullable: true) | |||
}, | |||
constraints: table => | |||
{ | |||
table.PrimaryKey("PK_payments", x => x.Id); | |||
table.ForeignKey( | |||
name: "FK_payments_cardtypes_CardTypeId", | |||
column: x => x.CardTypeId, | |||
principalSchema: "ordering", | |||
principalTable: "cardtypes", | |||
principalColumn: "Id", | |||
onDelete: ReferentialAction.Cascade); | |||
}); | |||
migrationBuilder.CreateTable( | |||
name: "orders", | |||
schema: "ordering", | |||
columns: table => new | |||
{ | |||
Id = table.Column<int>(nullable: false), | |||
BillingAddressId = table.Column<int>(nullable: true), | |||
BuyerId = table.Column<int>(nullable: false), | |||
OrderDate = table.Column<DateTime>(nullable: false), | |||
PaymentId = table.Column<int>(nullable: false), | |||
ShippingAddressId = table.Column<int>(nullable: true), | |||
StatusId = table.Column<int>(nullable: false) | |||
}, | |||
constraints: table => | |||
{ | |||
table.PrimaryKey("PK_orders", x => x.Id); | |||
table.ForeignKey( | |||
name: "FK_orders_address_BillingAddressId", | |||
column: x => x.BillingAddressId, | |||
principalSchema: "ordering", | |||
principalTable: "address", | |||
principalColumn: "Id", | |||
onDelete: ReferentialAction.SetNull); | |||
table.ForeignKey( | |||
name: "FK_orders_buyers_BuyerId", | |||
column: x => x.BuyerId, | |||
principalSchema: "ordering", | |||
principalTable: "buyers", | |||
principalColumn: "Id", | |||
onDelete: ReferentialAction.Cascade); | |||
table.ForeignKey( | |||
name: "FK_orders_payments_PaymentId", | |||
column: x => x.PaymentId, | |||
principalSchema: "ordering", | |||
principalTable: "payments", | |||
principalColumn: "Id", | |||
onDelete: ReferentialAction.Cascade); | |||
table.ForeignKey( | |||
name: "FK_orders_address_ShippingAddressId", | |||
column: x => x.ShippingAddressId, | |||
principalSchema: "ordering", | |||
principalTable: "address", | |||
principalColumn: "Id", | |||
onDelete: ReferentialAction.Restrict); | |||
table.ForeignKey( | |||
name: "FK_orders_orderstatus_StatusId", | |||
column: x => x.StatusId, | |||
principalSchema: "ordering", | |||
principalTable: "orderstatus", | |||
principalColumn: "Id", | |||
onDelete: ReferentialAction.Cascade); | |||
}); | |||
migrationBuilder.CreateTable( | |||
name: "orderItems", | |||
schema: "ordering", | |||
columns: table => new | |||
{ | |||
Id = table.Column<int>(nullable: false) | |||
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), | |||
Discount = table.Column<decimal>(nullable: false), | |||
OrderId = table.Column<int>(nullable: false), | |||
ProductId = table.Column<int>(nullable: false), | |||
ProductName = table.Column<string>(nullable: false), | |||
UnitPrice = table.Column<decimal>(nullable: false), | |||
Units = table.Column<int>(nullable: false, defaultValue: 1) | |||
}, | |||
constraints: table => | |||
{ | |||
table.PrimaryKey("PK_orderItems", x => x.Id); | |||
table.ForeignKey( | |||
name: "FK_orderItems_orders_OrderId", | |||
column: x => x.OrderId, | |||
principalSchema: "ordering", | |||
principalTable: "orders", | |||
principalColumn: "Id", | |||
onDelete: ReferentialAction.Cascade); | |||
}); | |||
migrationBuilder.CreateIndex( | |||
name: "IX_orders_BillingAddressId", | |||
schema: "ordering", | |||
table: "orders", | |||
column: "BillingAddressId"); | |||
migrationBuilder.CreateIndex( | |||
name: "IX_orders_BuyerId", | |||
schema: "ordering", | |||
table: "orders", | |||
column: "BuyerId"); | |||
migrationBuilder.CreateIndex( | |||
name: "IX_orders_PaymentId", | |||
schema: "ordering", | |||
table: "orders", | |||
column: "PaymentId"); | |||
migrationBuilder.CreateIndex( | |||
name: "IX_orders_ShippingAddressId", | |||
schema: "ordering", | |||
table: "orders", | |||
column: "ShippingAddressId"); | |||
migrationBuilder.CreateIndex( | |||
name: "IX_orders_StatusId", | |||
schema: "ordering", | |||
table: "orders", | |||
column: "StatusId"); | |||
migrationBuilder.CreateIndex( | |||
name: "IX_orderItems_OrderId", | |||
schema: "ordering", | |||
table: "orderItems", | |||
column: "OrderId"); | |||
migrationBuilder.CreateIndex( | |||
name: "IX_payments_CardTypeId", | |||
schema: "ordering", | |||
table: "payments", | |||
column: "CardTypeId"); | |||
} | |||
protected override void Down(MigrationBuilder migrationBuilder) | |||
{ | |||
migrationBuilder.DropSequence( | |||
name: "buyerseq", | |||
schema: "ordering"); | |||
migrationBuilder.DropSequence( | |||
name: "orderseq", | |||
schema: "ordering"); | |||
migrationBuilder.DropSequence( | |||
name: "paymentseq", | |||
schema: "ordering"); | |||
migrationBuilder.DropTable( | |||
name: "orderItems", | |||
schema: "ordering"); | |||
migrationBuilder.DropTable( | |||
name: "orders", | |||
schema: "ordering"); | |||
migrationBuilder.DropTable( | |||
name: "address", | |||
schema: "ordering"); | |||
migrationBuilder.DropTable( | |||
name: "buyers", | |||
schema: "ordering"); | |||
migrationBuilder.DropTable( | |||
name: "payments", | |||
schema: "ordering"); | |||
migrationBuilder.DropTable( | |||
name: "orderstatus", | |||
schema: "ordering"); | |||
migrationBuilder.DropTable( | |||
name: "cardtypes", | |||
schema: "ordering"); | |||
} | |||
} | |||
} |
@ -0,0 +1,226 @@ | |||
using System; | |||
using Microsoft.EntityFrameworkCore; | |||
using Microsoft.EntityFrameworkCore.Infrastructure; | |||
using Microsoft.EntityFrameworkCore.Metadata; | |||
using Microsoft.EntityFrameworkCore.Migrations; | |||
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure; | |||
namespace Ordering.API.Infrastructure.Migrations | |||
{ | |||
[DbContext(typeof(OrderingContext))] | |||
partial class OrderingContextModelSnapshot : ModelSnapshot | |||
{ | |||
protected override void BuildModel(ModelBuilder modelBuilder) | |||
{ | |||
modelBuilder | |||
.HasAnnotation("ProductVersion", "1.0.1") | |||
.HasAnnotation("SqlServer:Sequence:ordering.buyerseq", "'buyerseq', 'ordering', '1', '10', '', '', 'Int64', 'False'") | |||
.HasAnnotation("SqlServer:Sequence:ordering.orderseq", "'orderseq', 'ordering', '1', '10', '', '', 'Int64', 'False'") | |||
.HasAnnotation("SqlServer:Sequence:ordering.paymentseq", "'paymentseq', 'ordering', '1', '10', '', '', 'Int64', 'False'") | |||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", b => | |||
{ | |||
b.Property<int>("Id") | |||
.ValueGeneratedOnAdd(); | |||
b.Property<string>("City"); | |||
b.Property<string>("Country"); | |||
b.Property<string>("CountryCode"); | |||
b.Property<double>("Latitude"); | |||
b.Property<double>("Longitude"); | |||
b.Property<string>("State"); | |||
b.Property<string>("StateCode"); | |||
b.Property<string>("Street"); | |||
b.Property<string>("ZipCode"); | |||
b.HasKey("Id"); | |||
b.ToTable("address","ordering"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer", b => | |||
{ | |||
b.Property<int>("Id") | |||
.ValueGeneratedOnAdd() | |||
.HasAnnotation("SqlServer:HiLoSequenceName", "buyerseq") | |||
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") | |||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); | |||
b.Property<string>("FullName") | |||
.IsRequired() | |||
.HasAnnotation("MaxLength", 200); | |||
b.HasKey("Id"); | |||
b.ToTable("buyers","ordering"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.CardType", b => | |||
{ | |||
b.Property<int>("Id") | |||
.ValueGeneratedOnAdd(); | |||
b.Property<string>("Name"); | |||
b.HasKey("Id"); | |||
b.ToTable("cardtypes","ordering"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order", b => | |||
{ | |||
b.Property<int>("Id") | |||
.ValueGeneratedOnAdd() | |||
.HasAnnotation("SqlServer:HiLoSequenceName", "orderseq") | |||
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") | |||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); | |||
b.Property<int?>("BillingAddressId"); | |||
b.Property<int>("BuyerId"); | |||
b.Property<DateTime>("OrderDate"); | |||
b.Property<int>("PaymentId"); | |||
b.Property<int?>("ShippingAddressId"); | |||
b.Property<int>("StatusId"); | |||
b.HasKey("Id"); | |||
b.HasIndex("BillingAddressId"); | |||
b.HasIndex("BuyerId"); | |||
b.HasIndex("PaymentId"); | |||
b.HasIndex("ShippingAddressId"); | |||
b.HasIndex("StatusId"); | |||
b.ToTable("orders","ordering"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderItem", b => | |||
{ | |||
b.Property<int>("Id") | |||
.ValueGeneratedOnAdd(); | |||
b.Property<decimal>("Discount"); | |||
b.Property<int>("OrderId"); | |||
b.Property<int>("ProductId"); | |||
b.Property<string>("ProductName") | |||
.IsRequired(); | |||
b.Property<decimal>("UnitPrice"); | |||
b.Property<int>("Units") | |||
.ValueGeneratedOnAdd() | |||
.HasAnnotation("SqlServer:DefaultValue", 1); | |||
b.HasKey("Id"); | |||
b.HasIndex("OrderId"); | |||
b.ToTable("orderItems","ordering"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderStatus", b => | |||
{ | |||
b.Property<int>("Id") | |||
.ValueGeneratedOnAdd(); | |||
b.Property<string>("Name"); | |||
b.HasKey("Id"); | |||
b.ToTable("orderstatus","ordering"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", b => | |||
{ | |||
b.Property<int>("Id") | |||
.ValueGeneratedOnAdd() | |||
.HasAnnotation("SqlServer:HiLoSequenceName", "paymentseq") | |||
.HasAnnotation("SqlServer:HiLoSequenceSchema", "ordering") | |||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); | |||
b.Property<string>("CardHolderName") | |||
.IsRequired() | |||
.HasAnnotation("MaxLength", 200); | |||
b.Property<string>("CardNumber") | |||
.IsRequired() | |||
.HasAnnotation("MaxLength", 25); | |||
b.Property<int>("CardTypeId"); | |||
b.Property<DateTime>("Expiration"); | |||
b.Property<string>("SecurityNumber"); | |||
b.HasKey("Id"); | |||
b.HasIndex("CardTypeId"); | |||
b.ToTable("payments","ordering"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order", b => | |||
{ | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", "BillingAddress") | |||
.WithMany() | |||
.HasForeignKey("BillingAddressId") | |||
.OnDelete(DeleteBehavior.SetNull); | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Buyer", "Buyer") | |||
.WithMany() | |||
.HasForeignKey("BuyerId") | |||
.OnDelete(DeleteBehavior.Cascade); | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", "Payment") | |||
.WithMany() | |||
.HasForeignKey("PaymentId") | |||
.OnDelete(DeleteBehavior.Cascade); | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Address", "ShippingAddress") | |||
.WithMany() | |||
.HasForeignKey("ShippingAddressId"); | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderStatus", "Status") | |||
.WithMany() | |||
.HasForeignKey("StatusId") | |||
.OnDelete(DeleteBehavior.Cascade); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.OrderItem", b => | |||
{ | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.Order") | |||
.WithMany("OrderItems") | |||
.HasForeignKey("OrderId") | |||
.OnDelete(DeleteBehavior.Cascade); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.Payment", b => | |||
{ | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.CardType", "CardType") | |||
.WithMany() | |||
.HasForeignKey("CardTypeId") | |||
.OnDelete(DeleteBehavior.Cascade); | |||
}); | |||
} | |||
} | |||
} |
@ -0,0 +1,26 @@ | |||
| |||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure | |||
{ | |||
using AspNetCore.Builder; | |||
using Microsoft.EntityFrameworkCore; | |||
using Ordering.Infrastructure; | |||
using System.Threading.Tasks; | |||
public class OrderingContextSeed | |||
{ | |||
public static async Task SeedAsync(IApplicationBuilder applicationBuilder) | |||
{ | |||
var context = (OrderingContext)applicationBuilder | |||
.ApplicationServices.GetService(typeof(OrderingContext)); | |||
using (context) | |||
{ | |||
context.Database.Migrate(); | |||
await context.SaveChangesAsync(); | |||
} | |||
} | |||
} | |||
} |
@ -1,3 +1,3 @@ | |||
{ | |||
"ConnectionString": "Server=127.0.0.1;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;" | |||
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;" | |||
} |
@ -1,13 +1,38 @@ | |||
| |||
namespace Microsoft.eShopOnContainers.Services.Ordering.Application.Queries | |||
namespace Microsoft.eShopOnContainers.Services.Ordering.Application.Queries | |||
{ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using Dapper; | |||
using Microsoft.Extensions.Configuration; | |||
using System.Data.SqlClient; | |||
using System.Threading.Tasks; | |||
public class OrderQueries | |||
:IOrderQueries | |||
{ | |||
private string _connectionString = string.Empty; | |||
public OrderQueries(IConfiguration configuration) | |||
{ | |||
_connectionString = configuration["ConnectionString"]; | |||
} | |||
public async Task<dynamic> GetOrder(int id) | |||
{ | |||
using (var connection = new SqlConnection(_connectionString)) | |||
{ | |||
connection.Open(); | |||
return await connection.QueryAsync<dynamic>("SELECT * FROM ordering.Orders where Id=@id",new { id }); | |||
} | |||
} | |||
public async Task<dynamic> GetPendingOrders() | |||
{ | |||
using (var connection = new SqlConnection(_connectionString)) | |||
{ | |||
connection.Open(); | |||
return await connection.QueryAsync<dynamic>("SELECT * FROM ordering.Orders"); | |||
} | |||
} | |||
} | |||
} |
@ -0,0 +1,57 @@ | |||
| |||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain | |||
{ | |||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
public class CardType | |||
: Entity | |||
{ | |||
public static CardType Amex = new CardType(1, "Amex"); | |||
public static CardType Visa = new CardType(1, "Visa"); | |||
public static CardType MasterCard = new CardType(1, "MasterCard"); | |||
public string Name { get; private set; } | |||
protected CardType() { } | |||
public CardType(int id, string name) | |||
{ | |||
Id = id; | |||
Name = name; | |||
} | |||
public static IEnumerable<CardType> List() | |||
{ | |||
return new[] { Amex, Visa, MasterCard }; | |||
} | |||
public static CardType FromName(string name) | |||
{ | |||
var state = List() | |||
.SingleOrDefault(s => String.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase)); | |||
if (state == null) | |||
{ | |||
throw new ArgumentException($"Possible values for CardType: {String.Join(",", List().Select(s => s.Name))}"); | |||
} | |||
return state; | |||
} | |||
public static CardType From(int id) | |||
{ | |||
var state = List().SingleOrDefault(s => s.Id == id); | |||
if (state == null) | |||
{ | |||
throw new ArgumentException($"Possible values for CardType: {String.Join(",", List().Select(s => s.Name))}"); | |||
} | |||
return state; | |||
} | |||
} | |||
} |
@ -0,0 +1,27 @@ | |||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain | |||
{ | |||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
public class Payment | |||
: Entity, IAggregateRoot | |||
{ | |||
public string CardNumber { get; private set; } | |||
public string SecurityNumber { get; private set; } | |||
public string CardHolderName { get; private set; } | |||
public int CardTypeId { get; private set; } | |||
public CardType CardType { get; private set; } | |||
public DateTime Expiration { get; private set; } | |||
protected Payment() { } | |||
} | |||
} |
@ -1,126 +0,0 @@ | |||
| |||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork | |||
{ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using System.Reflection; | |||
public class ValueObject<TValueObject> : IEquatable<TValueObject> | |||
where TValueObject : ValueObject<TValueObject> | |||
{ | |||
//A ValueObject doesn't have Identity, but we just need an Id/key so EF knows how to persist | |||
//becuase in EF Core it still doesn't support ValueObjects or ComplexTypes | |||
//This should be changed when EF Core supports any of those. | |||
// https://github.com/aspnet/EntityFramework/issues/246 | |||
public virtual Guid Id { get; protected set; } | |||
//IEquatable and Override Equals operators | |||
public bool Equals(TValueObject other) | |||
{ | |||
if ((object)other == null) | |||
return false; | |||
if (Object.ReferenceEquals(this, other)) | |||
return true; | |||
//compare all public properties | |||
PropertyInfo[] publicProperties = this.GetType().GetProperties(); | |||
if ((object)publicProperties != null | |||
&& | |||
publicProperties.Any()) | |||
{ | |||
return publicProperties.All(p => | |||
{ | |||
var left = p.GetValue(this, null); | |||
var right = p.GetValue(other, null); | |||
if (typeof(TValueObject).IsAssignableFrom(left.GetType())) | |||
{ | |||
//check not self-references... | |||
return Object.ReferenceEquals(left, right); | |||
} | |||
else | |||
return left.Equals(right); | |||
}); | |||
} | |||
else | |||
return true; | |||
} | |||
public override bool Equals(object obj) | |||
{ | |||
if ((object)obj == null) | |||
return false; | |||
if (Object.ReferenceEquals(this, obj)) | |||
return true; | |||
ValueObject<TValueObject> item = obj as ValueObject<TValueObject>; | |||
if ((object)item != null) | |||
return Equals((TValueObject)item); | |||
else | |||
return false; | |||
} | |||
public override int GetHashCode() | |||
{ | |||
int hashCode = 31; | |||
bool changeMultiplier = false; | |||
int index = 1; | |||
//compare all public properties | |||
PropertyInfo[] publicProperties = this.GetType().GetProperties(); | |||
if ((object)publicProperties != null | |||
&& | |||
publicProperties.Any()) | |||
{ | |||
foreach (var item in publicProperties) | |||
{ | |||
object value = item.GetValue(this, null); | |||
if ((object)value != null) | |||
{ | |||
hashCode = hashCode * ((changeMultiplier) ? 59 : 114) + value.GetHashCode(); | |||
changeMultiplier = !changeMultiplier; | |||
} | |||
else | |||
hashCode = hashCode ^ (index * 13);//only for support {"a",null,null,"a"} <> {null,"a","a",null} | |||
} | |||
} | |||
return hashCode; | |||
} | |||
public static bool operator ==(ValueObject<TValueObject> left, ValueObject<TValueObject> right) | |||
{ | |||
if (Object.Equals(left, null)) | |||
return (Object.Equals(right, null)) ? true : false; | |||
else | |||
return left.Equals(right); | |||
} | |||
public static bool operator !=(ValueObject<TValueObject> left, ValueObject<TValueObject> right) | |||
{ | |||
return !(left == right); | |||
} | |||
} | |||
} | |||
@ -0,0 +1,138 @@ | |||
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure | |||
{ | |||
using Microsoft.EntityFrameworkCore; | |||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | |||
using Microsoft.eShopOnContainers.Services.Ordering.Domain; | |||
public class OrderingContext | |||
: DbContext | |||
{ | |||
const string DEFAULT_SCHEMA = "ordering"; | |||
public DbSet<Order> Orders { get; set; } | |||
public DbSet<OrderItem> OrderItems { get; set; } | |||
public DbSet<Payment> Payments { get; set; } | |||
public DbSet<Buyer> Buyers { get; set; } | |||
public DbSet<CardType> Cards { get; set; } | |||
public DbSet<OrderStatus> OrderStatus { get; set; } | |||
public DbSet<Address> Addresses { get; set; } | |||
public OrderingContext(DbContextOptions options) : base(options) { } | |||
protected override void OnModelCreating(ModelBuilder modelBuilder) | |||
{ | |||
modelBuilder.Entity<Buyer>(ConfigureBuyer); | |||
modelBuilder.Entity<Payment>(ConfigurePayment); | |||
modelBuilder.Entity<Order>(ConfigureOrder); | |||
modelBuilder.Entity<OrderItem>(ConfigureOrderItems); | |||
modelBuilder.Entity<OrderStatus>() | |||
.ToTable("orderstatus", DEFAULT_SCHEMA); | |||
modelBuilder.Entity<CardType>() | |||
.ToTable("cardtypes", DEFAULT_SCHEMA); | |||
modelBuilder.Entity<Address>() | |||
.ToTable("address", DEFAULT_SCHEMA); | |||
} | |||
void ConfigureBuyer(EntityTypeBuilder<Buyer> buyerConfiguration) | |||
{ | |||
buyerConfiguration.ToTable("buyers", DEFAULT_SCHEMA); | |||
buyerConfiguration.HasKey(b => b.Id); | |||
buyerConfiguration.Property(b => b.Id) | |||
.ForSqlServerUseSequenceHiLo("buyerseq", DEFAULT_SCHEMA); | |||
buyerConfiguration.Property(b => b.FullName) | |||
.HasMaxLength(200) | |||
.IsRequired(); | |||
} | |||
void ConfigurePayment(EntityTypeBuilder<Payment> paymentConfiguration) | |||
{ | |||
paymentConfiguration.ToTable("payments", DEFAULT_SCHEMA); | |||
paymentConfiguration.HasKey(b => b.Id); | |||
paymentConfiguration.Property(b => b.Id) | |||
.ForSqlServerUseSequenceHiLo("paymentseq", DEFAULT_SCHEMA); | |||
paymentConfiguration.Property(p => p.CardHolderName) | |||
.HasMaxLength(200) | |||
.IsRequired(); | |||
paymentConfiguration.Property(p => p.CardNumber) | |||
.HasMaxLength(25) | |||
.IsRequired(); | |||
paymentConfiguration.Property(p => p.Expiration) | |||
.IsRequired(); | |||
paymentConfiguration.HasOne(p => p.CardType) | |||
.WithMany() | |||
.HasForeignKey(p => p.CardTypeId); | |||
} | |||
void ConfigureOrder(EntityTypeBuilder<Order> orderConfiguration) | |||
{ | |||
orderConfiguration.ToTable("orders", DEFAULT_SCHEMA); | |||
orderConfiguration.HasKey(o => o.Id); | |||
orderConfiguration.Property(o => o.Id) | |||
.ForSqlServerUseSequenceHiLo("orderseq", DEFAULT_SCHEMA); | |||
orderConfiguration.Property(o => o.OrderDate) | |||
.IsRequired(); | |||
orderConfiguration.HasOne(o => o.Payment) | |||
.WithMany() | |||
.HasForeignKey(o => o.PaymentId); | |||
orderConfiguration.HasOne(o => o.BillingAddress) | |||
.WithMany() | |||
.HasForeignKey(o => o.BillingAddressId) | |||
.OnDelete(EntityFrameworkCore.Metadata.DeleteBehavior.SetNull); | |||
orderConfiguration.HasOne(o => o.Buyer) | |||
.WithMany() | |||
.HasForeignKey(o => o.BuyerId); | |||
orderConfiguration.HasOne(o => o.Status) | |||
.WithMany() | |||
.HasForeignKey(o => o.StatusId); | |||
} | |||
void ConfigureOrderItems(EntityTypeBuilder<OrderItem> orderItemConfiguration) | |||
{ | |||
orderItemConfiguration.ToTable("orderItems", DEFAULT_SCHEMA); | |||
orderItemConfiguration.HasKey(o => o.Id); | |||
orderItemConfiguration.Property(o => o.Discount) | |||
.IsRequired(); | |||
orderItemConfiguration.Property(o => o.ProductId) | |||
.IsRequired(); | |||
orderItemConfiguration.Property(o => o.ProductName) | |||
.IsRequired(); | |||
orderItemConfiguration.Property(o => o.UnitPrice) | |||
.IsRequired(); | |||
orderItemConfiguration.Property(o => o.Units) | |||
.ForSqlServerHasDefaultValue(1) | |||
.IsRequired(); | |||
} | |||
} | |||
} |
@ -0,0 +1,16 @@ | |||
{ | |||
"version": "1.0.0-*", | |||
"dependencies": { | |||
"NETStandard.Library": "1.6.0", | |||
"Microsoft.EntityFrameworkCore": "1.0.1", | |||
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.1", | |||
"Ordering.Domain": "1.0.0-*" | |||
}, | |||
"frameworks": { | |||
"netstandard1.6": { | |||
"imports": "dnxcore50" | |||
} | |||
} | |||
} |
@ -1,50 +0,0 @@ | |||
using Microsoft.EntityFrameworkCore; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork | |||
{ | |||
public class DbContextUtil | |||
{ | |||
public static DbContextOptions<OrderingDbContext> CreateNewContextOptionsForInMemoryDB() | |||
{ | |||
// Create a fresh service provider, and therefore a fresh | |||
// InMemory database instance. | |||
var serviceProvider = new ServiceCollection() | |||
.AddEntityFrameworkInMemoryDatabase() | |||
.BuildServiceProvider(); | |||
// Create a new options instance telling the context to use an | |||
// InMemory database and the new service provider. | |||
var builder = new DbContextOptionsBuilder<OrderingDbContext>(); | |||
builder.UseInMemoryDatabase() | |||
.UseInternalServiceProvider(serviceProvider); | |||
return builder.Options; | |||
} | |||
public static DbContextOptions<OrderingDbContext> CreateNewContextOptionsForSqlDb() | |||
{ | |||
// Create a new options instance telling the context to use a Sql database | |||
var builder = new DbContextOptionsBuilder<OrderingDbContext>(); | |||
//SQL LocalDB | |||
//var connString = @"Server=(localdb)\mssqllocaldb;Database=Microsoft.eShopOnContainers.Services.OrderingDb;Trusted_Connection=True;"; | |||
//SQL SERVER on-premises | |||
//(Integrated Security) var connString = @"Server=CESARDLBOOKVHD;Database=Microsoft.eShopOnContainers.Services.OrderingDb;Trusted_Connection=True;"; | |||
//(SQL Server Authentication) | |||
var connString = @"Server=10.0.75.1;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;"; | |||
//SQL LOCALDB | |||
builder.UseSqlServer(connString); | |||
return builder.Options; | |||
} | |||
} | |||
} |
@ -1,82 +0,0 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using Microsoft.EntityFrameworkCore; | |||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel; | |||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork; | |||
namespace Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork | |||
{ | |||
public class OrderingDbContext : DbContext, IUnitOfWork | |||
{ | |||
public OrderingDbContext(DbContextOptions<OrderingDbContext> options) | |||
: base(options) | |||
{ } | |||
public DbSet<Order> Orders { get; set; } | |||
//(CDLTLL) | |||
/* | |||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | |||
{ | |||
//If running from ASP.NET Core, config is done at StartUp.cs --> ConfigureServices() outside | |||
//and injected through DI later on. The following config is used when running Tests or similar contexts | |||
if (!optionsBuilder.IsConfigured) | |||
{ | |||
//SQL LocalDB | |||
//var connString = @"Server=(localdb)\mssqllocaldb;Database=Microsoft.eShopOnContainers.Services.OrderingDb;Trusted_Connection=True;"; | |||
//SQL SERVER on-premises | |||
//(Integrated Security) | |||
//var connString = @"Server=CESARDLBOOKVHD;Database=Microsoft.eShopOnContainers.Services.OrderingDb;Trusted_Connection=True;"; | |||
//(SQL Server Authentication) | |||
var connString = @"Server=10.0.75.1;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;"; | |||
//SQL LOCALDB | |||
optionsBuilder.UseSqlServer(connString); | |||
} | |||
} | |||
*/ | |||
protected override void OnModelCreating(ModelBuilder modelBuilder) | |||
{ | |||
base.OnModelCreating(modelBuilder); | |||
// Add your customizations after calling base.OnModelCreating(builder); | |||
//Sequence to be used as part of the OrderNumber | |||
modelBuilder.HasSequence<int>("OrderSequences", schema: "shared") | |||
.StartsAt(1001) | |||
.IncrementsBy(1); | |||
modelBuilder.Entity<Order>() | |||
.Property(o => o.SequenceNumber) | |||
.HasDefaultValueSql("NEXT VALUE FOR shared.OrderSequences"); | |||
} | |||
public async Task<int> CommitAsync() | |||
{ | |||
int changes = 0; | |||
try | |||
{ | |||
//(CDLTLL) TBD | |||
//RemoveOrphanedChilds(); | |||
changes = await base.SaveChangesAsync(); | |||
} | |||
catch (Exception ex) | |||
{ | |||
//(CDLTLL) TBD | |||
//RejectChanges(); | |||
throw ex; | |||
} | |||
return changes; | |||
} | |||
} | |||
} |
@ -1,19 +0,0 @@ | |||
{ | |||
"version": "1.0.0-*", | |||
"dependencies": { | |||
"Microsoft.EntityFrameworkCore": "1.0.0", | |||
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0", | |||
"NETStandard.Library": "1.6.0", | |||
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0", | |||
"Ordering.Domain": "1.0.0-*", | |||
"Microsoft.EntityFrameworkCore.InMemory": "1.0.0" | |||
}, | |||
"frameworks": { | |||
"netstandard1.6": { | |||
"imports": [ "dnxcore50", "portable-net451+win8" ] | |||
} | |||
} | |||
} |
@ -1,86 +0,0 @@ | |||
using System; | |||
using System.Linq; | |||
using Xunit; | |||
using Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork; | |||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel; | |||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Contracts; | |||
using Microsoft.eShopOnContainers.Services.Ordering.SqlData.Repositories; | |||
using Microsoft.EntityFrameworkCore; | |||
namespace DataIntegrationTests | |||
{ | |||
//Basic documentation for Testing EF Core classes | |||
// http://ef.readthedocs.io/en/latest/miscellaneous/testing.html | |||
public class Tests | |||
{ | |||
[Fact] | |||
public async void Add_order_to_data_model() | |||
{ | |||
// All contexts that share the same service provider will share the same database | |||
//Using InMemory DB | |||
//var options = DbContextUtil.CreateNewContextOptionsForInMemoryDB(); | |||
//Using Sql Server | |||
var options = DbContextUtil.CreateNewContextOptionsForSqlDb(); | |||
// Run the test against one instance of the context | |||
using (var context = new OrderingDbContext(options)) | |||
{ | |||
IOrderRepository orderRepository = new OrderRepository(context); | |||
//Create generic Address ValueObject | |||
Address sampleAddress = new Address("15703 NE 61st Ct.", | |||
"Redmond", | |||
"Washington", | |||
"WA", | |||
"United States", | |||
"US", | |||
"98052", | |||
47.661492, | |||
-122.131309 | |||
); | |||
//Create sample Orders | |||
Order order1 = new Order(Guid.NewGuid(), sampleAddress, sampleAddress); | |||
//Add a few OrderItems | |||
order1.AddNewOrderItem(Guid.NewGuid(), 2, 25, 30); | |||
order1.AddNewOrderItem(Guid.NewGuid(), 1, 58, 0); | |||
order1.AddNewOrderItem(Guid.NewGuid(), 1, 60, 0); | |||
order1.AddNewOrderItem(Guid.NewGuid(), 3, 12, 0); | |||
order1.AddNewOrderItem(Guid.NewGuid(), 5, 3, 0); | |||
orderRepository.Add(order1); | |||
int numChanges = await orderRepository.UnitOfWork.CommitAsync(); | |||
//With no Async Repository | |||
//context.Orders.Add(order1); | |||
//context.SaveChanges(); | |||
} | |||
//// Use a separate instance of the context to verify correct data was saved to database | |||
using (var context = new OrderingDbContext(options)) | |||
{ | |||
var orders = context.Orders | |||
.Include(o => o.ShippingAddress) | |||
.Include(o => o.BillingAddress) | |||
.ToList(); | |||
//Could be using .Load() if you don't want to create a List | |||
//OTHER SAMPLE | |||
//var company = context.Companies | |||
// .Include(co => co.Employees).ThenInclude(emp => emp.Employee_Car) | |||
// .Include(co => co.Employees).ThenInclude(emp => emp.Employee_Country) | |||
// .FirstOrDefault(co => co.companyID == companyID); | |||
//Assert when running test with a clean In-Memory DB | |||
//Assert.Equal(1, context.Orders.Count()); | |||
string cityName = orders.First<Order>().ShippingAddress.City; | |||
Assert.Equal("Redmond", cityName); | |||
} | |||
} | |||
} | |||
} |