Skip to content

Commit cfa7039

Browse files
committed
initial efcore setup done
1 parent 98b339b commit cfa7039

File tree

4 files changed

+244
-0
lines changed

4 files changed

+244
-0
lines changed

CarvedRock/CarvedRock.Api/Migrations/20190912180018_Initial.Designer.cs

Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore.Metadata;
3+
using Microsoft.EntityFrameworkCore.Migrations;
4+
5+
namespace CarvedRock.Api.Migrations
6+
{
7+
public partial class Initial : Migration
8+
{
9+
protected override void Up(MigrationBuilder migrationBuilder)
10+
{
11+
migrationBuilder.CreateTable(
12+
name: "Products",
13+
columns: table => new
14+
{
15+
Id = table.Column<int>(nullable: false)
16+
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
17+
Name = table.Column<string>(maxLength: 100, nullable: false),
18+
Type = table.Column<int>(nullable: false),
19+
Description = table.Column<string>(nullable: false),
20+
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
21+
Stock = table.Column<int>(nullable: false),
22+
Rating = table.Column<int>(nullable: false),
23+
IntroducedAt = table.Column<DateTimeOffset>(nullable: false),
24+
PhotoFileName = table.Column<string>(maxLength: 100, nullable: true)
25+
},
26+
constraints: table =>
27+
{
28+
table.PrimaryKey("PK_Products", x => x.Id);
29+
});
30+
31+
migrationBuilder.CreateTable(
32+
name: "ProductReviews",
33+
columns: table => new
34+
{
35+
Id = table.Column<int>(nullable: false)
36+
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
37+
ProductId = table.Column<int>(nullable: false),
38+
Title = table.Column<string>(maxLength: 200, nullable: false),
39+
Review = table.Column<string>(nullable: true)
40+
},
41+
constraints: table =>
42+
{
43+
table.PrimaryKey("PK_ProductReviews", x => x.Id);
44+
table.ForeignKey(
45+
name: "FK_ProductReviews_Products_ProductId",
46+
column: x => x.ProductId,
47+
principalTable: "Products",
48+
principalColumn: "Id",
49+
onDelete: ReferentialAction.Cascade);
50+
});
51+
52+
migrationBuilder.CreateIndex(
53+
name: "IX_ProductReviews_ProductId",
54+
table: "ProductReviews",
55+
column: "ProductId");
56+
}
57+
58+
protected override void Down(MigrationBuilder migrationBuilder)
59+
{
60+
migrationBuilder.DropTable(
61+
name: "ProductReviews");
62+
63+
migrationBuilder.DropTable(
64+
name: "Products");
65+
}
66+
}
67+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// <auto-generated />
2+
using System;
3+
using CarvedRock.Api.Data;
4+
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.EntityFrameworkCore.Infrastructure;
6+
using Microsoft.EntityFrameworkCore.Metadata;
7+
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8+
9+
namespace CarvedRock.Api.Migrations
10+
{
11+
[DbContext(typeof(CarvedRockDbContext))]
12+
partial class CarvedRockDbContextModelSnapshot : ModelSnapshot
13+
{
14+
protected override void BuildModel(ModelBuilder modelBuilder)
15+
{
16+
#pragma warning disable 612, 618
17+
modelBuilder
18+
.HasAnnotation("ProductVersion", "2.2.6-servicing-10079")
19+
.HasAnnotation("Relational:MaxIdentifierLength", 128)
20+
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
21+
22+
modelBuilder.Entity("CarvedRock.Api.Data.Entities.Product", b =>
23+
{
24+
b.Property<int>("Id")
25+
.ValueGeneratedOnAdd()
26+
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
27+
28+
b.Property<string>("Description")
29+
.IsRequired();
30+
31+
b.Property<DateTimeOffset>("IntroducedAt");
32+
33+
b.Property<string>("Name")
34+
.IsRequired()
35+
.HasMaxLength(100);
36+
37+
b.Property<string>("PhotoFileName")
38+
.HasMaxLength(100);
39+
40+
b.Property<decimal>("Price")
41+
.HasColumnType("decimal(18,2)");
42+
43+
b.Property<int>("Rating");
44+
45+
b.Property<int>("Stock");
46+
47+
b.Property<int>("Type");
48+
49+
b.HasKey("Id");
50+
51+
b.ToTable("Products");
52+
});
53+
54+
modelBuilder.Entity("CarvedRock.Api.Data.Entities.ProductReview", b =>
55+
{
56+
b.Property<int>("Id")
57+
.ValueGeneratedOnAdd()
58+
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
59+
60+
b.Property<int>("ProductId");
61+
62+
b.Property<string>("Review");
63+
64+
b.Property<string>("Title")
65+
.IsRequired()
66+
.HasMaxLength(200);
67+
68+
b.HasKey("Id");
69+
70+
b.HasIndex("ProductId");
71+
72+
b.ToTable("ProductReviews");
73+
});
74+
75+
modelBuilder.Entity("CarvedRock.Api.Data.Entities.ProductReview", b =>
76+
{
77+
b.HasOne("CarvedRock.Api.Data.Entities.Product", "Product")
78+
.WithMany("ProductReviews")
79+
.HasForeignKey("ProductId")
80+
.OnDelete(DeleteBehavior.Cascade);
81+
});
82+
#pragma warning restore 612, 618
83+
}
84+
}
85+
}

CarvedRock/CarvedRock.Api/Startup.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Threading.Tasks;
5+
using CarvedRock.Api.Data;
56
using Microsoft.AspNetCore.Builder;
67
using Microsoft.AspNetCore.Hosting;
78
using Microsoft.AspNetCore.Mvc;
9+
using Microsoft.EntityFrameworkCore;
810
using Microsoft.Extensions.Configuration;
911
using Microsoft.Extensions.DependencyInjection;
1012
using Microsoft.Extensions.Logging;
@@ -24,6 +26,9 @@ public Startup(IConfiguration configuration)
2426
// This method gets called by the runtime. Use this method to add services to the container.
2527
public void ConfigureServices(IServiceCollection services)
2628
{
29+
services.AddDbContext<CarvedRockDbContext>(options =>
30+
options.UseSqlServer(Configuration["ConnectionStrings:CarvedRock"]));
31+
2732
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
2833
}
2934

0 commit comments

Comments
 (0)