@ -0,0 +1,89 @@ | |||
using System; | |||
using Microsoft.EntityFrameworkCore; | |||
using Microsoft.EntityFrameworkCore.Infrastructure; | |||
using Microsoft.EntityFrameworkCore.Metadata; | |||
using Microsoft.EntityFrameworkCore.Migrations; | |||
using Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork; | |||
namespace Ordering.API.Migrations | |||
{ | |||
[DbContext(typeof(OrderingDbContext))] | |||
[Migration("20160913052800_Migration4")] | |||
partial class Migration4 | |||
{ | |||
protected override void BuildTargetModel(ModelBuilder modelBuilder) | |||
{ | |||
modelBuilder | |||
.HasAnnotation("ProductVersion", "1.0.0-rtm-21431") | |||
.HasAnnotation("Relational:Sequence:shared.OrderSequences", "'OrderSequences', 'shared', '1001', '1', '', '', 'Int32', 'False'") | |||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", b => | |||
{ | |||
b.Property<Guid>("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"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b => | |||
{ | |||
b.Property<Guid>("Id") | |||
.ValueGeneratedOnAdd(); | |||
b.Property<Guid?>("BillingAddressId"); | |||
b.Property<Guid>("BuyerId"); | |||
b.Property<DateTime>("OrderDate"); | |||
b.Property<int>("SequenceNumber") | |||
.ValueGeneratedOnAdd() | |||
.HasDefaultValueSql("NEXT VALUE FOR shared.OrderSequences"); | |||
b.Property<Guid?>("ShippingAddressId"); | |||
b.Property<int>("Status"); | |||
b.HasKey("Id"); | |||
b.HasIndex("BillingAddressId"); | |||
b.HasIndex("ShippingAddressId"); | |||
b.ToTable("Orders"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b => | |||
{ | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", "BillingAddress") | |||
.WithMany() | |||
.HasForeignKey("BillingAddressId"); | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", "ShippingAddress") | |||
.WithMany() | |||
.HasForeignKey("ShippingAddressId"); | |||
}); | |||
} | |||
} | |||
} |
@ -0,0 +1,37 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using Microsoft.EntityFrameworkCore.Migrations; | |||
namespace Ordering.API.Migrations | |||
{ | |||
public partial class Migration4 : Migration | |||
{ | |||
protected override void Up(MigrationBuilder migrationBuilder) | |||
{ | |||
migrationBuilder.EnsureSchema( | |||
name: "shared"); | |||
migrationBuilder.CreateSequence<int>( | |||
name: "OrderSequences", | |||
schema: "shared", | |||
startValue: 1001L); | |||
migrationBuilder.AddColumn<int>( | |||
name: "SequenceNumber", | |||
table: "Orders", | |||
nullable: false, | |||
defaultValueSql: "NEXT VALUE FOR shared.OrderSequences"); | |||
} | |||
protected override void Down(MigrationBuilder migrationBuilder) | |||
{ | |||
migrationBuilder.DropSequence( | |||
name: "OrderSequences", | |||
schema: "shared"); | |||
migrationBuilder.DropColumn( | |||
name: "SequenceNumber", | |||
table: "Orders"); | |||
} | |||
} | |||
} |
@ -0,0 +1,121 @@ | |||
using System; | |||
using Microsoft.EntityFrameworkCore; | |||
using Microsoft.EntityFrameworkCore.Infrastructure; | |||
using Microsoft.EntityFrameworkCore.Metadata; | |||
using Microsoft.EntityFrameworkCore.Migrations; | |||
using Microsoft.eShopOnContainers.Services.Ordering.SqlData.UnitOfWork; | |||
namespace Ordering.API.Migrations | |||
{ | |||
[DbContext(typeof(OrderingDbContext))] | |||
[Migration("20160913061710_Migration5")] | |||
partial class Migration5 | |||
{ | |||
protected override void BuildTargetModel(ModelBuilder modelBuilder) | |||
{ | |||
modelBuilder | |||
.HasAnnotation("ProductVersion", "1.0.0-rtm-21431") | |||
.HasAnnotation("Relational:Sequence:shared.OrderSequences", "'OrderSequences', 'shared', '1001', '1', '', '', 'Int32', 'False'") | |||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", b => | |||
{ | |||
b.Property<Guid>("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"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b => | |||
{ | |||
b.Property<Guid>("Id") | |||
.ValueGeneratedOnAdd(); | |||
b.Property<Guid?>("BillingAddressId"); | |||
b.Property<Guid>("BuyerId"); | |||
b.Property<DateTime>("OrderDate"); | |||
b.Property<int>("SequenceNumber") | |||
.ValueGeneratedOnAdd() | |||
.HasDefaultValueSql("NEXT VALUE FOR shared.OrderSequences"); | |||
b.Property<Guid?>("ShippingAddressId"); | |||
b.Property<int>("Status"); | |||
b.HasKey("Id"); | |||
b.HasIndex("BillingAddressId"); | |||
b.HasIndex("ShippingAddressId"); | |||
b.ToTable("Orders"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderItem", b => | |||
{ | |||
b.Property<Guid>("Id") | |||
.ValueGeneratedOnAdd(); | |||
b.Property<decimal>("Discount"); | |||
b.Property<int>("FulfillmentRemaining"); | |||
b.Property<Guid>("OrderId"); | |||
b.Property<Guid>("ProductId"); | |||
b.Property<int>("Quantity"); | |||
b.Property<decimal>("UnitPrice"); | |||
b.HasKey("Id"); | |||
b.HasIndex("OrderId"); | |||
b.ToTable("OrderItem"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order", b => | |||
{ | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", "BillingAddress") | |||
.WithMany() | |||
.HasForeignKey("BillingAddressId"); | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Address", "ShippingAddress") | |||
.WithMany() | |||
.HasForeignKey("ShippingAddressId"); | |||
}); | |||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderItem", b => | |||
{ | |||
b.HasOne("Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Order") | |||
.WithMany("OrderItems") | |||
.HasForeignKey("OrderId") | |||
.OnDelete(DeleteBehavior.Cascade); | |||
}); | |||
} | |||
} | |||
} |
@ -0,0 +1,46 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using Microsoft.EntityFrameworkCore.Migrations; | |||
namespace Ordering.API.Migrations | |||
{ | |||
public partial class Migration5 : Migration | |||
{ | |||
protected override void Up(MigrationBuilder migrationBuilder) | |||
{ | |||
migrationBuilder.CreateTable( | |||
name: "OrderItem", | |||
columns: table => new | |||
{ | |||
Id = table.Column<Guid>(nullable: false), | |||
Discount = table.Column<decimal>(nullable: false), | |||
FulfillmentRemaining = table.Column<int>(nullable: false), | |||
OrderId = table.Column<Guid>(nullable: false), | |||
ProductId = table.Column<Guid>(nullable: false), | |||
Quantity = table.Column<int>(nullable: false), | |||
UnitPrice = table.Column<decimal>(nullable: false) | |||
}, | |||
constraints: table => | |||
{ | |||
table.PrimaryKey("PK_OrderItem", x => x.Id); | |||
table.ForeignKey( | |||
name: "FK_OrderItem_Orders_OrderId", | |||
column: x => x.OrderId, | |||
principalTable: "Orders", | |||
principalColumn: "Id", | |||
onDelete: ReferentialAction.Cascade); | |||
}); | |||
migrationBuilder.CreateIndex( | |||
name: "IX_OrderItem_OrderId", | |||
table: "OrderItem", | |||
column: "OrderId"); | |||
} | |||
protected override void Down(MigrationBuilder migrationBuilder) | |||
{ | |||
migrationBuilder.DropTable( | |||
name: "OrderItem"); | |||
} | |||
} | |||
} |
@ -0,0 +1,40 @@ | |||
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 | |||
builder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Microsoft.eShopOnContainers.Services.OrderingDb;Trusted_Connection=True;"); | |||
return builder.Options; | |||
} | |||
} | |||
} |