SuharevaContext.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace YtYtAvalonia.Models;
  5. public partial class SuharevaContext : DbContext
  6. {
  7. public SuharevaContext()
  8. {
  9. AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
  10. }
  11. public SuharevaContext(DbContextOptions<SuharevaContext> options)
  12. : base(options)
  13. {
  14. }
  15. public virtual DbSet<Availability> Availabilities { get; set; }
  16. public virtual DbSet<Course> Courses { get; set; }
  17. public virtual DbSet<User> Users { get; set; }
  18. public virtual DbSet<UserAndCourse> UserAndCourses { get; set; }
  19. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  20. #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.
  21. => optionsBuilder.UseNpgsql("Host=edu.pg.ngknn.ru;Port=5442;Database=Suhareva;Username=33P;Password=12345");
  22. protected override void OnModelCreating(ModelBuilder modelBuilder)
  23. {
  24. modelBuilder.Entity<Availability>(entity =>
  25. {
  26. entity.HasKey(e => e.Availabilityid).HasName("Availability_pkey");
  27. entity.ToTable("Availability");
  28. entity.Property(e => e.Availabilityid)
  29. .UseIdentityAlwaysColumn()
  30. .HasColumnName("availabilityid");
  31. entity.Property(e => e.Title)
  32. .HasMaxLength(50)
  33. .HasColumnName("title");
  34. });
  35. modelBuilder.Entity<Course>(entity =>
  36. {
  37. entity.HasKey(e => e.Courseid).HasName("Course_pkey");
  38. entity.ToTable("Course");
  39. entity.Property(e => e.Courseid)
  40. .UseIdentityAlwaysColumn()
  41. .HasColumnName("courseid");
  42. entity.Property(e => e.Availability).HasColumnName("availability");
  43. entity.Property(e => e.Price).HasColumnName("price");
  44. entity.Property(e => e.Title)
  45. .HasMaxLength(50)
  46. .HasColumnName("title");
  47. entity.HasOne(d => d.AvailabilityNavigation).WithMany(p => p.Courses)
  48. .HasForeignKey(d => d.Availability)
  49. .OnDelete(DeleteBehavior.ClientSetNull)
  50. .HasConstraintName("Course_availability_fkey");
  51. });
  52. modelBuilder.Entity<User>(entity =>
  53. {
  54. entity.HasKey(e => e.Userid).HasName("User_pkey");
  55. entity.ToTable("User");
  56. entity.Property(e => e.Userid)
  57. .UseIdentityAlwaysColumn()
  58. .HasColumnName("userid");
  59. entity.Property(e => e.Bithday).HasColumnName("bithday");
  60. entity.Property(e => e.Email)
  61. .HasMaxLength(50)
  62. .HasColumnName("email");
  63. entity.Property(e => e.Login)
  64. .HasMaxLength(50)
  65. .HasColumnName("login");
  66. entity.Property(e => e.Name).HasMaxLength(50);
  67. entity.Property(e => e.Password).HasMaxLength(50);
  68. entity.Property(e => e.Patronymic)
  69. .HasMaxLength(50)
  70. .HasColumnName("patronymic");
  71. entity.Property(e => e.Phonenumber).HasColumnName("phonenumber");
  72. entity.Property(e => e.Surname)
  73. .HasMaxLength(50)
  74. .HasColumnName("surname");
  75. });
  76. modelBuilder.Entity<UserAndCourse>(entity =>
  77. {
  78. entity
  79. .HasNoKey()
  80. .ToTable("UserAndCourse");
  81. entity.Property(e => e.Courseid).HasColumnName("courseid");
  82. entity.Property(e => e.Userid).HasColumnName("userid");
  83. entity.HasOne(d => d.Course).WithMany()
  84. .HasForeignKey(d => d.Courseid)
  85. .OnDelete(DeleteBehavior.ClientSetNull)
  86. .HasConstraintName("UserAndCourse_courseid_fkey");
  87. entity.HasOne(d => d.User).WithMany()
  88. .HasForeignKey(d => d.Userid)
  89. .OnDelete(DeleteBehavior.ClientSetNull)
  90. .HasConstraintName("UserAndCourse_userid_fkey");
  91. });
  92. OnModelCreatingPartial(modelBuilder);
  93. }
  94. partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
  95. }