You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuUtilsDbContext.cs 1.9KB

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