PostgresContext.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace exam.Models;
  5. public partial class PostgresContext : DbContext
  6. {
  7. public PostgresContext()
  8. {
  9. }
  10. public PostgresContext(DbContextOptions<PostgresContext> options)
  11. : base(options)
  12. {
  13. }
  14. public virtual DbSet<Country> Countries { get; set; }
  15. public virtual DbSet<User> Users { get; set; }
  16. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  17. #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.
  18. => optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=plo030803a");
  19. protected override void OnModelCreating(ModelBuilder modelBuilder)
  20. {
  21. modelBuilder.HasPostgresExtension("pg_catalog", "adminpack");
  22. modelBuilder.Entity<Country>(entity =>
  23. {
  24. entity.HasKey(e => e.Id).HasName("countries_pkey");
  25. entity.ToTable("countries");
  26. entity.Property(e => e.Id).HasColumnName("id");
  27. entity.Property(e => e.Country1)
  28. .HasMaxLength(100)
  29. .HasColumnName("country");
  30. });
  31. modelBuilder.Entity<User>(entity =>
  32. {
  33. entity.HasKey(e => e.Id).HasName("users_pkey");
  34. entity.ToTable("users");
  35. entity.Property(e => e.Id).HasColumnName("id");
  36. entity.Property(e => e.Firstname)
  37. .HasMaxLength(100)
  38. .HasColumnName("firstname");
  39. entity.Property(e => e.Idcountry).HasColumnName("idcountry");
  40. entity.Property(e => e.Lastname)
  41. .HasMaxLength(100)
  42. .HasColumnName("lastname");
  43. entity.Property(e => e.Loginuser)
  44. .HasMaxLength(100)
  45. .HasColumnName("loginuser");
  46. entity.Property(e => e.Passworsuser)
  47. .HasMaxLength(100)
  48. .HasColumnName("passworsuser");
  49. entity.HasOne(d => d.IdcountryNavigation).WithMany(p => p.Users)
  50. .HasForeignKey(d => d.Idcountry)
  51. .HasConstraintName("users_idcountry_fkey");
  52. });
  53. OnModelCreatingPartial(modelBuilder);
  54. }
  55. partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
  56. }