PostgresContext.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace AvaloniaApplication4.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<Product> Products { get; set; }
  15. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  16. #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.
  17. => optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=123qwe12qw");
  18. protected override void OnModelCreating(ModelBuilder modelBuilder)
  19. {
  20. modelBuilder.HasPostgresExtension("pg_catalog", "adminpack");
  21. modelBuilder.Entity<Product>(entity =>
  22. {
  23. entity
  24. .HasNoKey()
  25. .ToTable("product");
  26. entity.Property(e => e.Color)
  27. .HasMaxLength(20)
  28. .HasColumnName("color");
  29. entity.Property(e => e.Count).HasColumnName("count");
  30. entity.Property(e => e.Country)
  31. .HasMaxLength(40)
  32. .HasColumnName("country");
  33. entity.Property(e => e.Id).HasColumnName("id");
  34. entity.Property(e => e.Price)
  35. .HasColumnType("money")
  36. .HasColumnName("price");
  37. entity.Property(e => e.Аutomobile).HasMaxLength(40);
  38. });
  39. OnModelCreatingPartial(modelBuilder);
  40. }
  41. partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
  42. }