ICollection 사용
public ICollection<Student> m_listLandSiteDataText { get; set; }
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "CourseId",
table: "Students",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_Students_CourseId",
table: "Students",
column: "CourseId");
migrationBuilder.AddForeignKey(
name: "FK_Students_Courses_CourseId",
table: "Students",
column: "CourseId",
principalTable: "Courses",
principalColumn: "CourseId",
onDelete: ReferentialAction.Restrict);
}
Index와 ForeignKey 없이 생성
[ForeignKey("Course")]
public int CourseId { get; set; }
[ForeignKey("CourseId")]
public int CourseId { get; set; }
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "CourseId",
table: "Students",
nullable: false,
defaultValue: 0);
}
virtual 사용시
public int CourseId { get; set; }
[ForeignKey("CourseId")]
public virtual Course m_mvLandSiteDataImage { get; set; }
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "CourseId",
table: "Students",
nullable: false,
defaultValue: 0);
migrationBuilder.CreateIndex(
name: "IX_Students_CourseId",
table: "Students",
column: "CourseId");
migrationBuilder.AddForeignKey(
name: "FK_Students_Courses_CourseId",
table: "Students",
column: "CourseId",
principalTable: "Courses",
principalColumn: "CourseId",
onDelete: ReferentialAction.Cascade);
}

Leave a Reply