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 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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<pk_bigserial>()
  27. .HasKey(c => new { c.id });
  28. modelBuilder.Entity<pk_bigserial>()
  29. .Property(e => e.id)
  30. .HasDefaultValueSql("nextval('pk_bigserial_id_seq'::regclass)");
  31. modelBuilder.Entity<pk_bigserial>()
  32. .Property(e => e.created_at)
  33. .HasDefaultValueSql("now()");
  34. modelBuilder.Entity<pk_guid>()
  35. .HasKey(c => new { c.id });
  36. modelBuilder.Entity<pk_guid>()
  37. .Property(e => e.id)
  38. .HasDefaultValueSql("get_uuid()");
  39. modelBuilder.Entity<pk_guid>()
  40. .Property(e => e.created_at)
  41. .HasDefaultValueSql("now()");
  42. }
  43. public virtual DbSet<pk_bigserial> pk_bigserial { get; set; }
  44. public virtual DbSet<pk_guid> pk_guid { get; set; }
  45. }
  46. }