(MVC) MVC (2018)

<<назадSchoolContext.vb (Contoso University).

   1:  Imports System.Data.Entity
   2:   
   3:  Public Class SchoolContext
   4:          Inherits Entity.DbContext
   5:   
   6:      Public Sub New()
   7:          Database.SetInitializer(New MigrateDatabaseToLatestVersion(Of SchoolContext, Migrations.Configuration)(NameOf(SchoolContext)))
   8:      End Sub
   9:   
  10:      Public Property Courses As Entity.DbSet(Of Models.Course)
  11:   
  12:          Public Property Enrollments As Entity.DbSet(Of Models.Enrollment)
  13:   
  14:          Public Property Students As Entity.DbSet(Of Models.Student)
  15:   
  16:          Public Property Departments As Entity.DbSet(Of Models.Department)
  17:   
  18:          Public Property Instructors As Entity.DbSet(Of Models.Instructor)
  19:   
  20:          Public Property OfficeAssignments As Entity.DbSet(Of Models.OfficeAssignment)
  21:   
  22:          Public Property CourseAssignments As Entity.DbSet(Of Models.CourseAssignment)
  23:   
  24:          Public Property People As Entity.DbSet(Of Models.Person)
  25:   
  26:          Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
  27:              modelBuilder.Entity(Of Models.Course)().ToTable(NameOf(Models.Course))
  28:              modelBuilder.Entity(Of Models.Enrollment)().ToTable(NameOf(Models.Enrollment))
  29:              modelBuilder.Entity(Of Models.Student)().ToTable(NameOf(Models.Student))
  30:              modelBuilder.Entity(Of Models.Department)().ToTable(NameOf(Models.Department))
  31:              modelBuilder.Entity(Of Models.Instructor)().ToTable(NameOf(Models.Instructor))
  32:              modelBuilder.Entity(Of Models.OfficeAssignment)().ToTable(NameOf(Models.OfficeAssignment))
  33:              modelBuilder.Entity(Of Models.CourseAssignment)().ToTable(NameOf(Models.CourseAssignment))
  34:              modelBuilder.Entity(Of Models.Person)().ToTable(NameOf(Models.Person))
  35:              modelBuilder.Entity(Of Models.CourseAssignment)().HasKey(Function(c) New With {c.CourseID, c.InstructorID})
  36:          End Sub
  37:   
  38:      End Class


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