Skip to content

Commit e3413b3

Browse files
committed
Address model created and added as FK in the Customer model.
1 parent cf9a16a commit e3413b3

8 files changed

+748
-0
lines changed

Database/OnlineStoreContext.cs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class OnlineStoreContext : DbContext
88
public OnlineStoreContext(DbContextOptions<OnlineStoreContext> options) : base(options) { }
99

1010
public DbSet<Customer> Customers { get; set; }
11+
public DbSet<Address> Addresses { get; set; }
1112
public DbSet<NewsletterEmail> NewsletterEmails { get; set; }
1213
public DbSet<Collaborator> Collaborators { get; set; }
1314
public DbSet<Category> Categories { get; set; }

Migrations/20200614212907_AddressesTableCreated.Designer.cs

+264
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
namespace OnlineStore.Migrations
4+
{
5+
public partial class AddressesTableCreated : Migration
6+
{
7+
protected override void Up(MigrationBuilder migrationBuilder)
8+
{
9+
migrationBuilder.AlterColumn<string>(
10+
name: "Name",
11+
table: "Products",
12+
nullable: false,
13+
oldClrType: typeof(string),
14+
oldType: "nvarchar(max)",
15+
oldNullable: true);
16+
17+
migrationBuilder.AlterColumn<string>(
18+
name: "Description",
19+
table: "Products",
20+
nullable: false,
21+
oldClrType: typeof(string),
22+
oldType: "nvarchar(max)",
23+
oldNullable: true);
24+
25+
migrationBuilder.CreateTable(
26+
name: "Addresses",
27+
columns: table => new
28+
{
29+
Id = table.Column<int>(nullable: false)
30+
.Annotation("SqlServer:Identity", "1, 1"),
31+
Cep = table.Column<string>(maxLength: 8, nullable: false),
32+
State = table.Column<string>(nullable: false),
33+
City = table.Column<string>(nullable: false),
34+
Neighborhood = table.Column<string>(nullable: false),
35+
AddressLine = table.Column<string>(nullable: false),
36+
Complement = table.Column<string>(nullable: true),
37+
Number = table.Column<string>(nullable: false)
38+
},
39+
constraints: table =>
40+
{
41+
table.PrimaryKey("PK_Addresses", x => x.Id);
42+
});
43+
}
44+
45+
protected override void Down(MigrationBuilder migrationBuilder)
46+
{
47+
migrationBuilder.DropTable(
48+
name: "Addresses");
49+
50+
migrationBuilder.AlterColumn<string>(
51+
name: "Name",
52+
table: "Products",
53+
type: "nvarchar(max)",
54+
nullable: true,
55+
oldClrType: typeof(string));
56+
57+
migrationBuilder.AlterColumn<string>(
58+
name: "Description",
59+
table: "Products",
60+
type: "nvarchar(max)",
61+
nullable: true,
62+
oldClrType: typeof(string));
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)