Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

LuUtilsDbContext.cs 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using Microsoft.EntityFrameworkCore;
  2. using TestUtils.DataAccess.Models;
  3. namespace TestUtils.DataAccess
  4. {
  5. public partial class LuUtilsDbContext : DbContext
  6. {
  7. private readonly string _connectionString;
  8. public LuUtilsDbContext()
  9. {
  10. }
  11. public LuUtilsDbContext(string connectionString)
  12. {
  13. _connectionString = connectionString;
  14. }
  15. public LuUtilsDbContext(DbContextOptions options) :base(options)
  16. {
  17. }
  18. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  19. {
  20. if (_connectionString != null) {
  21. optionsBuilder.UseNpgsql(_connectionString);
  22. }
  23. }
  24. protected override void OnModelCreating(ModelBuilder modelBuilder)
  25. {
  26. modelBuilder.Entity<fk_pk_guids>()
  27. .HasKey(c => new { c.id });
  28. modelBuilder.Entity<fk_pk_guids>()
  29. .Property(e => e.id)
  30. .HasDefaultValueSql("get_uuid()");
  31. modelBuilder.Entity<fk_pk_guids>()
  32. .HasOne(e => e.fk_pk_guid)
  33. .WithMany(e => e.fk_pk_guids_fk)
  34. .HasForeignKey("pk_guid_id")
  35. .HasConstraintName("fk_pk_guid_pk_guid_id_fkey");
  36. modelBuilder.Entity<pk_bigserial>()
  37. .HasKey(c => new { c.id });
  38. modelBuilder.Entity<pk_bigserial>()
  39. .Property(e => e.id)
  40. .HasDefaultValueSql("nextval('pk_bigserial_id_seq'::regclass)");
  41. modelBuilder.Entity<pk_bigserial>()
  42. .Property(e => e.created_at)
  43. .HasDefaultValueSql("now()");
  44. modelBuilder.Entity<pk_guid>()
  45. .HasKey(c => new { c.id });
  46. modelBuilder.Entity<pk_guid>()
  47. .Property(e => e.id)
  48. .HasDefaultValueSql("get_uuid()");
  49. modelBuilder.Entity<pk_guid>()
  50. .Property(e => e.created_at)
  51. .HasDefaultValueSql("now()");
  52. }
  53. public virtual DbSet<fk_pk_guids> fk_pk_guids { get; set; }
  54. public virtual DbSet<pk_bigserial> pk_bigserial { get; set; }
  55. public virtual DbSet<pk_guid> pk_guid { get; set; }
  56. }
  57. }