123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using System;
- using System.Collections.Generic;
- using Microsoft.EntityFrameworkCore;
- namespace AvaloniaExample.Models;
- public partial class UsersContext : DbContext
- {
- public UsersContext()
- {
- }
- public UsersContext(DbContextOptions<UsersContext> options)
- : base(options)
- {
- }
- public virtual DbSet<Login> Logins { get; set; }
- public virtual DbSet<Subject> Subjects { get; set; }
- public virtual DbSet<TeacherSubject> TeacherSubjects { get; set; }
- public virtual DbSet<UsersInfo> UsersInfos { get; set; }
- protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
- #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.
- => optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=Users;Username=postgres;Password=123");
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
- modelBuilder
- .HasPostgresEnum("genders", new[] { "мужчина", "женщина" })
- .HasPostgresEnum("roles", new[] { "администратор", "преподаватель", "студент" });
- modelBuilder.Entity<Login>(entity =>
- {
- entity.HasKey(e => e.Id).HasName("logins_pkey");
- entity.ToTable("logins");
- entity.HasIndex(e => e.Value, "login_unique").IsUnique();
- entity.Property(e => e.Id).HasColumnName("id");
- entity.Property(e => e.Role).HasColumnName("role");
- entity.Property(e => e.Value)
- .HasMaxLength(40)
- .HasColumnName("login");
- entity.Property(e => e.Password)
- .HasMaxLength(40)
- .HasColumnName("password");
- });
- modelBuilder.Entity<Subject>(entity =>
- {
- entity.HasKey(e => e.Id).HasName("subjects_pkey");
- entity.ToTable("subjects");
- entity.Property(e => e.Id).HasColumnName("id");
- entity.Property(e => e.Description)
- .HasMaxLength(300)
- .HasColumnName("description");
- entity.Property(e => e.Name)
- .HasMaxLength(60)
- .HasColumnName("name");
- });
- modelBuilder.Entity<TeacherSubject>(entity =>
- {
- entity
- .HasNoKey()
- .ToTable("teacher_subject");
- entity.Property(e => e.Login)
- .HasMaxLength(40)
- .HasColumnName("login");
- entity.Property(e => e.Subject).HasColumnName("subject");
- entity.HasOne(d => d.LoginNavigation).WithMany()
- .HasForeignKey(d => d.Login)
- .HasConstraintName("teacher_subject_login_fkey");
- entity.HasOne(d => d.SubjectNavigation).WithMany()
- .HasForeignKey(d => d.Subject)
- .HasConstraintName("teacher_subject_subject_fkey");
- });
- modelBuilder.Entity<UsersInfo>(entity =>
- {
- entity.HasKey(e => e.Login).HasName("users_info_pkey");
- entity.ToTable("users_info");
- entity.HasIndex(e => e.Mail, "users_info_mail_key").IsUnique();
- entity.HasIndex(e => e.Phone, "users_info_phone_key").IsUnique();
- entity.Property(e => e.Login)
- .HasMaxLength(40)
- .HasColumnName("login");
- entity.Property(e => e.DateBirth).HasColumnName("date_birth");
- entity.Property(e => e.Gender).HasColumnName("gender");
- entity.Property(e => e.Mail)
- .HasMaxLength(60)
- .HasColumnName("mail");
- entity.Property(e => e.Name)
- .HasMaxLength(200)
- .HasColumnName("name");
- entity.Property(e => e.Phone)
- .HasMaxLength(20)
- .HasColumnName("phone");
- entity.HasOne(d => d.LoginNavigation).WithOne(p => p.UsersInfo)
- .HasPrincipalKey<Login>(p => p.Value)
- .HasForeignKey<UsersInfo>(d => d.Login)
- .OnDelete(DeleteBehavior.ClientSetNull)
- .HasConstraintName("users_info_login_fkey");
- });
- OnModelCreatingPartial(modelBuilder);
- }
- partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
- }
|