(MVC) MVC (2018)

<<назад 201801202344102_InitialCreate.vb (Contoso University).

   1:  Imports System
   2:  Imports System.Data.Entity.Migrations
   3:  Imports Microsoft.VisualBasic
   4:   
   5:  Namespace Migrations
   6:      Public Partial Class InitialCreate
   7:          Inherits DbMigration
   8:      
   9:          Public Overrides Sub Up()
  10:              CreateTable(
  11:                  "dbo.CourseAssignment",
  12:                  Function(c) New With
  13:                      {
  14:                          .CourseID = c.Int(nullable := False),
  15:                          .InstructorID = c.Int(nullable := False)
  16:                      }) _
  17:                  .PrimaryKey(Function(t) New With { t.CourseID, t.InstructorID }) _
  18:                  .ForeignKey("dbo.Course", Function(t) t.CourseID, cascadeDelete := True) _
  19:                  .ForeignKey("dbo.Instructor", Function(t) t.InstructorID) _
  20:                  .Index(Function(t) t.CourseID) _
  21:                  .Index(Function(t) t.InstructorID)
  22:              
  23:              CreateTable(
  24:                  "dbo.Course",
  25:                  Function(c) New With
  26:                      {
  27:                          .CourseID = c.Int(nullable := False),
  28:                          .Title = c.String(maxLength := 50),
  29:                          .Credits = c.Int(nullable := False),
  30:                          .DepartmentID = c.Int(nullable := False)
  31:                      }) _
  32:                  .PrimaryKey(Function(t) t.CourseID) _
  33:                  .ForeignKey("dbo.Department", Function(t) t.DepartmentID, cascadeDelete := True) _
  34:                  .Index(Function(t) t.DepartmentID)
  35:              
  36:              CreateTable(
  37:                  "dbo.Department",
  38:                  Function(c) New With
  39:                      {
  40:                          .DepartmentID = c.Int(nullable := False, identity := True),
  41:                          .Name = c.String(maxLength := 50),
  42:                          .Budget = c.Decimal(nullable := False, storeType := "money"),
  43:                          .StartDate = c.DateTime(nullable := False),
  44:                          .InstructorID = c.Int(),
  45:                          .RowVersion = c.Binary(nullable := False, fixedLength := true, timestamp := True, storeType := "rowversion")
  46:                      }) _
  47:                  .PrimaryKey(Function(t) t.DepartmentID) _
  48:                  .ForeignKey("dbo.Instructor", Function(t) t.InstructorID) _
  49:                  .Index(Function(t) t.InstructorID)
  50:              
  51:              CreateTable(
  52:                  "dbo.Person",
  53:                  Function(c) New With
  54:                      {
  55:                          .ID = c.Int(nullable := False, identity := True),
  56:                          .LastName = c.String(nullable := False, maxLength := 50),
  57:                          .FirstName = c.String(nullable := False, maxLength := 50)
  58:                      }) _
  59:                  .PrimaryKey(Function(t) t.ID)
  60:              
  61:              CreateTable(
  62:                  "dbo.OfficeAssignment",
  63:                  Function(c) New With
  64:                      {
  65:                          .InstructorID = c.Int(nullable := False, identity := True),
  66:                          .Location = c.String(maxLength := 50),
  67:                          .Instructor_ID = c.Int()
  68:                      }) _
  69:                  .PrimaryKey(Function(t) t.InstructorID) _
  70:                  .ForeignKey("dbo.Instructor", Function(t) t.Instructor_ID) _
  71:                  .Index(Function(t) t.Instructor_ID)
  72:              
  73:              CreateTable(
  74:                  "dbo.Enrollment",
  75:                  Function(c) New With
  76:                      {
  77:                          .EnrollmentID = c.Int(nullable := False, identity := True),
  78:                          .CourseID = c.Int(nullable := False),
  79:                          .StudentID = c.Int(nullable := False),
  80:                          .Grade = c.Int()
  81:                      }) _
  82:                  .PrimaryKey(Function(t) t.EnrollmentID) _
  83:                  .ForeignKey("dbo.Course", Function(t) t.CourseID, cascadeDelete := True) _
  84:                  .ForeignKey("dbo.Student", Function(t) t.StudentID) _
  85:                  .Index(Function(t) t.CourseID) _
  86:                  .Index(Function(t) t.StudentID)
  87:              
  88:              CreateTable(
  89:                  "dbo.Instructor",
  90:                  Function(c) New With
  91:                      {
  92:                          .ID = c.Int(nullable := False),
  93:                          .HireDate = c.DateTime(nullable := False)
  94:                      }) _
  95:                  .PrimaryKey(Function(t) t.ID) _
  96:                  .ForeignKey("dbo.Person", Function(t) t.ID) _
  97:                  .Index(Function(t) t.ID)
  98:              
  99:              CreateTable(
 100:                  "dbo.Student",
 101:                  Function(c) New With
 102:                      {
 103:                          .ID = c.Int(nullable := False),
 104:                          .EnrollmentDate = c.DateTime(nullable := False)
 105:                      }) _
 106:                  .PrimaryKey(Function(t) t.ID) _
 107:                  .ForeignKey("dbo.Person", Function(t) t.ID) _
 108:                  .Index(Function(t) t.ID)
 109:              
 110:          End Sub
 111:          
 112:          Public Overrides Sub Down()
 113:              DropForeignKey("dbo.Student", "ID", "dbo.Person")
 114:              DropForeignKey("dbo.Instructor", "ID", "dbo.Person")
 115:              DropForeignKey("dbo.Enrollment", "StudentID", "dbo.Student")
 116:              DropForeignKey("dbo.Enrollment", "CourseID", "dbo.Course")
 117:              DropForeignKey("dbo.Course", "DepartmentID", "dbo.Department")
 118:              DropForeignKey("dbo.Department", "InstructorID", "dbo.Instructor")
 119:              DropForeignKey("dbo.OfficeAssignment", "Instructor_ID", "dbo.Instructor")
 120:              DropForeignKey("dbo.CourseAssignment", "InstructorID", "dbo.Instructor")
 121:              DropForeignKey("dbo.CourseAssignment", "CourseID", "dbo.Course")
 122:              DropIndex("dbo.Student", New String() { "ID" })
 123:              DropIndex("dbo.Instructor", New String() { "ID" })
 124:              DropIndex("dbo.Enrollment", New String() { "StudentID" })
 125:              DropIndex("dbo.Enrollment", New String() { "CourseID" })
 126:              DropIndex("dbo.OfficeAssignment", New String() { "Instructor_ID" })
 127:              DropIndex("dbo.Department", New String() { "InstructorID" })
 128:              DropIndex("dbo.Course", New String() { "DepartmentID" })
 129:              DropIndex("dbo.CourseAssignment", New String() { "InstructorID" })
 130:              DropIndex("dbo.CourseAssignment", New String() { "CourseID" })
 131:              DropTable("dbo.Student")
 132:              DropTable("dbo.Instructor")
 133:              DropTable("dbo.Enrollment")
 134:              DropTable("dbo.OfficeAssignment")
 135:              DropTable("dbo.Person")
 136:              DropTable("dbo.Department")
 137:              DropTable("dbo.Course")
 138:              DropTable("dbo.CourseAssignment")
 139:          End Sub
 140:      End Class
 141:  End Namespace


Comments ( )
Link to this page: //www.vb-net.com/EF-missing-FAQ/Code/201801202344102_InitialCreate.vb.htm
< THANKS ME>