@@ -1203,41 +1203,45 @@ <h3>Adding Database Migration</h3>
1203
1203
< img class ="img-thumbnail " alt ="Entity Framework Migration " src ="images/phonebook-migrations-core-4.png " /> </ p >
1204
1204
< p > This will create a new code based migration file to create < strong > PbPhones</ strong >
1205
1205
table:</ p >
1206
- < pre lang ="cs ">
1207
- public partial class Added_Persons_Table : Migration
1206
+ < pre lang ="cs "> public partial class Added_Phone : Migration
1208
1207
{
1209
1208
protected override void Up(MigrationBuilder migrationBuilder)
1210
1209
{
1211
1210
migrationBuilder.CreateTable(
1212
- name: "PbPersons ",
1211
+ name: "PbPhones ",
1213
1212
columns: table => new
1214
1213
{
1215
- Id = table.Column<int >(nullable: false)
1214
+ Id = table.Column<long >(nullable: false)
1216
1215
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
1217
1216
CreationTime = table.Column<DateTime>(nullable: false),
1218
1217
CreatorUserId = table.Column<long>(nullable: true),
1219
- DeleterUserId = table.Column<long>(nullable: true),
1220
- DeletionTime = table.Column<DateTime>(nullable: true),
1221
- EmailAddress = table.Column<string>(maxLength: 255, nullable: true),
1222
- IsDeleted = table.Column<bool>(nullable: false),
1223
- LastModificationTime = table.Column<DateTime>(nullable: true),
1224
- LastModifierUserId = table.Column<long>(nullable: true),
1225
- Name = table.Column<string>(maxLength: 32, nullable: false),
1226
- Surname = table.Column<string>(maxLength: 32, nullable: false)
1218
+ Number = table.Column<string>(maxLength: 16, nullable: false),
1219
+ PersonId = table.Column<int>(nullable: false),
1220
+ Type = table.Column<byte>(nullable: false)
1227
1221
},
1228
1222
constraints: table =>
1229
1223
{
1230
- table.PrimaryKey("PK_PbPersons", x => x.Id);
1224
+ table.PrimaryKey("PK_PbPhones", x => x.Id);
1225
+ table.ForeignKey(
1226
+ name: "FK_PbPhones_PbPersons_PersonId",
1227
+ column: x => x.PersonId,
1228
+ principalTable: "PbPersons",
1229
+ principalColumn: "Id",
1230
+ onDelete: ReferentialAction.Cascade);
1231
1231
});
1232
+
1233
+ migrationBuilder.CreateIndex(
1234
+ name: "IX_PbPhones_PersonId",
1235
+ table: "PbPhones",
1236
+ column: "PersonId");
1232
1237
}
1233
1238
1234
1239
protected override void Down(MigrationBuilder migrationBuilder)
1235
1240
{
1236
1241
migrationBuilder.DropTable(
1237
- name: "PbPersons ");
1242
+ name: "PbPhones ");
1238
1243
}
1239
- }
1240
- </ pre >
1244
+ }</ pre >
1241
1245
< p > Before updating database, we can go to database < strong > InitialPeopleCreator</ strong > , rename it to < strong > InitialPeopleAndPhoneCreator</ strong >
1242
1246
and add example < strong > phone numbers</ strong > for example people (We renamed
1243
1247
InitialPeopleCreator.cs to InitialPeopleAndPhoneCreator.cs):</ p >
0 commit comments