AvaloniaPrakt12DbContext.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace Prak12;
  5. public partial class AvaloniaPrakt12DbContext : DbContext
  6. {
  7. public AvaloniaPrakt12DbContext()
  8. {
  9. }
  10. public AvaloniaPrakt12DbContext(DbContextOptions<AvaloniaPrakt12DbContext> options)
  11. : base(options)
  12. {
  13. }
  14. public virtual DbSet<Course> Courses { get; set; }
  15. public virtual DbSet<Gender> Genders { get; set; }
  16. public virtual DbSet<Subject> Subjects { get; set; }
  17. public virtual DbSet<Teacher> Teachers { get; set; }
  18. public virtual DbSet<TeachersCourse> TeachersCourses { get; set; }
  19. public virtual DbSet<TeachersSubject> TeachersSubjects { get; set; }
  20. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  21. #warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
  22. => optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=AvaloniaPrakt12DB;Username=postgres;Password=k08760365");
  23. protected override void OnModelCreating(ModelBuilder modelBuilder)
  24. {
  25. modelBuilder.Entity<Course>(entity =>
  26. {
  27. entity.HasKey(e => e.IdCourse).HasName("courses_pk");
  28. entity.ToTable("courses");
  29. entity.Property(e => e.IdCourse)
  30. .UseIdentityAlwaysColumn()
  31. .HasColumnName("id_course");
  32. entity.Property(e => e.CourseHoursNumber).HasColumnName("course_hours_number");
  33. entity.Property(e => e.CourseName)
  34. .HasColumnType("character varying")
  35. .HasColumnName("course_name");
  36. });
  37. modelBuilder.Entity<Gender>(entity =>
  38. {
  39. entity.HasKey(e => e.IdGender).HasName("gender_pk");
  40. entity.ToTable("genders");
  41. entity.Property(e => e.IdGender)
  42. .UseIdentityAlwaysColumn()
  43. .HasColumnName("id_gender");
  44. entity.Property(e => e.GenderName)
  45. .HasColumnType("character varying")
  46. .HasColumnName("gender_name");
  47. });
  48. modelBuilder.Entity<Subject>(entity =>
  49. {
  50. entity.HasKey(e => e.IdSubjects).HasName("items_pk");
  51. entity.ToTable("subjects");
  52. entity.Property(e => e.IdSubjects)
  53. .UseIdentityAlwaysColumn()
  54. .HasColumnName("id_subjects");
  55. entity.Property(e => e.SubjectName)
  56. .HasColumnType("character varying")
  57. .HasColumnName("subject_name");
  58. });
  59. modelBuilder.Entity<Teacher>(entity =>
  60. {
  61. entity.HasKey(e => e.IdTeacher).HasName("teachers_pk");
  62. entity.ToTable("teachers");
  63. entity.Property(e => e.IdTeacher)
  64. .UseIdentityAlwaysColumn()
  65. .HasColumnName("id_teacher");
  66. entity.Property(e => e.IdGender).HasColumnName("id_gender");
  67. entity.Property(e => e.TeacherBirthdate).HasColumnName("teacher_birthdate");
  68. entity.Property(e => e.TeacherEmail)
  69. .HasColumnType("character varying")
  70. .HasColumnName("teacher_email");
  71. entity.Property(e => e.TeacherName)
  72. .HasColumnType("character varying")
  73. .HasColumnName("teacher_name");
  74. entity.Property(e => e.TeacherPatronymic)
  75. .HasColumnType("character varying")
  76. .HasColumnName("teacher_patronymic");
  77. entity.Property(e => e.TeacherPhoneNumber)
  78. .HasColumnType("character varying")
  79. .HasColumnName("teacher_phone_number");
  80. entity.Property(e => e.TeacherSurname)
  81. .HasColumnType("character varying")
  82. .HasColumnName("teacher_surname");
  83. entity.Property(e => e.TeacherWorkTime).HasColumnName("teacher_work_time");
  84. entity.HasOne(d => d.IdGenderNavigation).WithMany(p => p.Teachers)
  85. .HasForeignKey(d => d.IdGender)
  86. .HasConstraintName("teachers_fk");
  87. });
  88. modelBuilder.Entity<TeachersCourse>(entity =>
  89. {
  90. entity.HasKey(e => e.IdRecord).HasName("teachers_courses_pk");
  91. entity.ToTable("teachers_courses");
  92. entity.Property(e => e.IdRecord)
  93. .UseIdentityAlwaysColumn()
  94. .HasColumnName("id_record");
  95. entity.Property(e => e.IdCourse).HasColumnName("id_course");
  96. entity.Property(e => e.IdTeacher).HasColumnName("id_teacher");
  97. entity.HasOne(d => d.IdCourseNavigation).WithMany(p => p.TeachersCourses)
  98. .HasForeignKey(d => d.IdCourse)
  99. .OnDelete(DeleteBehavior.ClientSetNull)
  100. .HasConstraintName("teachers_courses_fk_1");
  101. entity.HasOne(d => d.IdTeacherNavigation).WithMany(p => p.TeachersCourses)
  102. .HasForeignKey(d => d.IdTeacher)
  103. .OnDelete(DeleteBehavior.ClientSetNull)
  104. .HasConstraintName("teachers_courses_fk");
  105. });
  106. modelBuilder.Entity<TeachersSubject>(entity =>
  107. {
  108. entity.HasKey(e => e.IdRecord).HasName("teachers_subjects_pk");
  109. entity.ToTable("teachers_subjects");
  110. entity.Property(e => e.IdRecord)
  111. .UseIdentityAlwaysColumn()
  112. .HasColumnName("id_record");
  113. entity.Property(e => e.IdSubject).HasColumnName("id_subject");
  114. entity.Property(e => e.IdTeacher).HasColumnName("id_teacher");
  115. entity.HasOne(d => d.IdSubjectNavigation).WithMany(p => p.TeachersSubjects)
  116. .HasForeignKey(d => d.IdSubject)
  117. .OnDelete(DeleteBehavior.ClientSetNull)
  118. .HasConstraintName("teachers_subjects_fk");
  119. entity.HasOne(d => d.IdTeacherNavigation).WithMany(p => p.TeachersSubjects)
  120. .HasForeignKey(d => d.IdTeacher)
  121. .OnDelete(DeleteBehavior.ClientSetNull)
  122. .HasConstraintName("teachers_subjects_fk_1");
  123. });
  124. OnModelCreatingPartial(modelBuilder);
  125. }
  126. partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
  127. }