UsersContext.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace AvaloniaExample.Models;
  5. public partial class UsersContext : DbContext
  6. {
  7. public UsersContext()
  8. {
  9. }
  10. public UsersContext(DbContextOptions<UsersContext> options)
  11. : base(options)
  12. {
  13. }
  14. public virtual DbSet<Login> Logins { get; set; }
  15. public virtual DbSet<Subject> Subjects { get; set; }
  16. public virtual DbSet<TeacherSubject> TeacherSubjects { get; set; }
  17. public virtual DbSet<UsersInfo> UsersInfos { get; set; }
  18. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  19. #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.
  20. => optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=Users;Username=postgres;Password=123");
  21. protected override void OnModelCreating(ModelBuilder modelBuilder)
  22. {
  23. modelBuilder
  24. .HasPostgresEnum("genders", new[] { "мужчина", "женщина" })
  25. .HasPostgresEnum("roles", new[] { "администратор", "преподаватель", "студент" });
  26. modelBuilder.Entity<Login>(entity =>
  27. {
  28. entity.HasKey(e => e.Id).HasName("logins_pkey");
  29. entity.ToTable("logins");
  30. entity.HasIndex(e => e.Value, "login_unique").IsUnique();
  31. entity.Property(e => e.Id).HasColumnName("id");
  32. entity.Property(e => e.Role).HasColumnName("role");
  33. entity.Property(e => e.Value)
  34. .HasMaxLength(40)
  35. .HasColumnName("login");
  36. entity.Property(e => e.Password)
  37. .HasMaxLength(40)
  38. .HasColumnName("password");
  39. });
  40. modelBuilder.Entity<Subject>(entity =>
  41. {
  42. entity.HasKey(e => e.Id).HasName("subjects_pkey");
  43. entity.ToTable("subjects");
  44. entity.Property(e => e.Id).HasColumnName("id");
  45. entity.Property(e => e.Description)
  46. .HasMaxLength(300)
  47. .HasColumnName("description");
  48. entity.Property(e => e.Name)
  49. .HasMaxLength(60)
  50. .HasColumnName("name");
  51. });
  52. modelBuilder.Entity<TeacherSubject>(entity =>
  53. {
  54. entity
  55. .HasNoKey()
  56. .ToTable("teacher_subject");
  57. entity.Property(e => e.Login)
  58. .HasMaxLength(40)
  59. .HasColumnName("login");
  60. entity.Property(e => e.Subject).HasColumnName("subject");
  61. entity.HasOne(d => d.LoginNavigation).WithMany()
  62. .HasForeignKey(d => d.Login)
  63. .HasConstraintName("teacher_subject_login_fkey");
  64. entity.HasOne(d => d.SubjectNavigation).WithMany()
  65. .HasForeignKey(d => d.Subject)
  66. .HasConstraintName("teacher_subject_subject_fkey");
  67. });
  68. modelBuilder.Entity<UsersInfo>(entity =>
  69. {
  70. entity.HasKey(e => e.Login).HasName("users_info_pkey");
  71. entity.ToTable("users_info");
  72. entity.HasIndex(e => e.Mail, "users_info_mail_key").IsUnique();
  73. entity.HasIndex(e => e.Phone, "users_info_phone_key").IsUnique();
  74. entity.Property(e => e.Login)
  75. .HasMaxLength(40)
  76. .HasColumnName("login");
  77. entity.Property(e => e.DateBirth).HasColumnName("date_birth");
  78. entity.Property(e => e.Gender).HasColumnName("gender");
  79. entity.Property(e => e.Mail)
  80. .HasMaxLength(60)
  81. .HasColumnName("mail");
  82. entity.Property(e => e.Name)
  83. .HasMaxLength(200)
  84. .HasColumnName("name");
  85. entity.Property(e => e.Phone)
  86. .HasMaxLength(20)
  87. .HasColumnName("phone");
  88. entity.HasOne(d => d.LoginNavigation).WithOne(p => p.UsersInfo)
  89. .HasPrincipalKey<Login>(p => p.Value)
  90. .HasForeignKey<UsersInfo>(d => d.Login)
  91. .OnDelete(DeleteBehavior.ClientSetNull)
  92. .HasConstraintName("users_info_login_fkey");
  93. });
  94. OnModelCreatingPartial(modelBuilder);
  95. }
  96. partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
  97. }