AvaloniaPrakt13DbContext.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace prakt1314;
  5. public partial class AvaloniaPrakt13DbContext : DbContext
  6. {
  7. public AvaloniaPrakt13DbContext()
  8. {
  9. }
  10. public AvaloniaPrakt13DbContext(DbContextOptions<AvaloniaPrakt13DbContext> options)
  11. : base(options)
  12. {
  13. }
  14. public virtual DbSet<Cource> Cources { get; set; }
  15. public virtual DbSet<TeacherCource> TeacherCources { get; set; }
  16. public virtual DbSet<UserDatum> UserData { get; set; }
  17. public virtual DbSet<UserGender> UserGenders { get; set; }
  18. public virtual DbSet<UserLogin> UserLogins { get; set; }
  19. public virtual DbSet<UserRole> UserRoles { 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=AvaloniaPrakt13DB;Username=postgres;Password=k08760365");
  23. protected override void OnModelCreating(ModelBuilder modelBuilder)
  24. {
  25. modelBuilder.Entity<Cource>(entity =>
  26. {
  27. entity.HasKey(e => e.IdCource).HasName("cource_pk");
  28. entity.ToTable("cource", "DB");
  29. entity.Property(e => e.IdCource)
  30. .UseIdentityAlwaysColumn()
  31. .HasColumnName("id_cource");
  32. entity.Property(e => e.Cource1).HasColumnName("cource");
  33. entity.Property(e => e.HoursNumber).HasColumnName("hours_number");
  34. });
  35. modelBuilder.Entity<TeacherCource>(entity =>
  36. {
  37. entity.HasKey(e => e.IdRecord).HasName("teacher_cource_pk");
  38. entity.ToTable("teacher_cource", "DB");
  39. entity.Property(e => e.IdRecord)
  40. .UseIdentityAlwaysColumn()
  41. .HasColumnName("id_record");
  42. entity.Property(e => e.IdCource).HasColumnName("id_cource");
  43. entity.Property(e => e.IdTeacher).HasColumnName("id_teacher");
  44. entity.HasOne(d => d.IdCourceNavigation).WithMany(p => p.TeacherCources)
  45. .HasForeignKey(d => d.IdCource)
  46. .OnDelete(DeleteBehavior.ClientSetNull)
  47. .HasConstraintName("teacher_cource_fk");
  48. entity.HasOne(d => d.IdTeacherNavigation).WithMany(p => p.TeacherCources)
  49. .HasForeignKey(d => d.IdTeacher)
  50. .OnDelete(DeleteBehavior.ClientSetNull)
  51. .HasConstraintName("teacher_cource_fk_1");
  52. });
  53. modelBuilder.Entity<UserDatum>(entity =>
  54. {
  55. entity.HasKey(e => e.IdUser).HasName("user_data_pk");
  56. entity.ToTable("user_data", "DB");
  57. entity.Property(e => e.IdUser)
  58. .ValueGeneratedNever()
  59. .HasColumnName("id_user");
  60. entity.Property(e => e.Birthdate)
  61. .HasColumnType("timestamp without time zone")
  62. .HasColumnName("birthdate");
  63. entity.Property(e => e.Email)
  64. .HasColumnType("character varying")
  65. .HasColumnName("email");
  66. entity.Property(e => e.IdGender).HasColumnName("id_gender");
  67. entity.Property(e => e.Name)
  68. .HasColumnType("character varying")
  69. .HasColumnName("name");
  70. entity.Property(e => e.Patronymic)
  71. .HasColumnType("character varying")
  72. .HasColumnName("patronymic");
  73. entity.Property(e => e.PhoneNumber)
  74. .HasColumnType("character varying")
  75. .HasColumnName("phone_number");
  76. entity.Property(e => e.Surname)
  77. .HasColumnType("character varying")
  78. .HasColumnName("surname");
  79. entity.Property(e => e.Worktime).HasColumnName("worktime");
  80. entity.HasOne(d => d.IdGenderNavigation).WithMany(p => p.UserData)
  81. .HasForeignKey(d => d.IdGender)
  82. .OnDelete(DeleteBehavior.ClientSetNull)
  83. .HasConstraintName("user_data_fk2");
  84. entity.HasOne(d => d.IdUserNavigation).WithOne(p => p.UserDatum)
  85. .HasForeignKey<UserDatum>(d => d.IdUser)
  86. .OnDelete(DeleteBehavior.ClientSetNull)
  87. .HasConstraintName("user_data_fk");
  88. });
  89. modelBuilder.Entity<UserGender>(entity =>
  90. {
  91. entity.HasKey(e => e.IdGender).HasName("user_gender_pk");
  92. entity.ToTable("user_gender", "DB");
  93. entity.Property(e => e.IdGender)
  94. .UseIdentityAlwaysColumn()
  95. .HasColumnName("id_gender");
  96. entity.Property(e => e.Gender)
  97. .HasColumnType("character varying")
  98. .HasColumnName("gender");
  99. });
  100. modelBuilder.Entity<UserLogin>(entity =>
  101. {
  102. entity.HasKey(e => e.IdUser).HasName("user_login_pk");
  103. entity.ToTable("user_login", "DB");
  104. entity.Property(e => e.IdUser)
  105. .UseIdentityAlwaysColumn()
  106. .HasColumnName("id_user");
  107. entity.Property(e => e.IdRole).HasColumnName("id_role");
  108. entity.Property(e => e.Login)
  109. .HasColumnType("character varying")
  110. .HasColumnName("login");
  111. entity.Property(e => e.Password)
  112. .HasColumnType("character varying")
  113. .HasColumnName("password");
  114. entity.HasOne(d => d.IdRoleNavigation).WithMany(p => p.UserLogins)
  115. .HasForeignKey(d => d.IdRole)
  116. .OnDelete(DeleteBehavior.ClientSetNull)
  117. .HasConstraintName("user_login_fk");
  118. });
  119. modelBuilder.Entity<UserRole>(entity =>
  120. {
  121. entity.HasKey(e => e.IdRole).HasName("user_roles_pk");
  122. entity.ToTable("user_roles", "DB");
  123. entity.Property(e => e.IdRole)
  124. .UseIdentityAlwaysColumn()
  125. .HasColumnName("id_role");
  126. entity.Property(e => e.RoleName)
  127. .HasColumnType("character varying")
  128. .HasColumnName("role_name");
  129. });
  130. OnModelCreatingPartial(modelBuilder);
  131. }
  132. partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
  133. }