SuharevaContext.cs 4.3 KB

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