InvestContext.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace InvestTracker.Entities;
  5. public partial class InvestContext : DbContext
  6. {
  7. public InvestContext()
  8. {
  9. }
  10. public InvestContext(DbContextOptions<InvestContext> options)
  11. : base(options)
  12. {
  13. }
  14. public virtual DbSet<Employee> Employees { get; set; }
  15. public virtual DbSet<Title> Titles { get; set; }
  16. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  17. {
  18. try {
  19. optionsBuilder.UseSqlServer("Data Source=srv-wsr\\is3;Initial Catalog=invest;User ID=user12;Password=user12;Encrypt=False");
  20. } catch {
  21. optionsBuilder.UseSqlServer("Data Source=vpmt.ru\\is3;Initial Catalog=invest;User ID=user12;Password=user12;Encrypt=False");
  22. }
  23. }
  24. protected override void OnModelCreating(ModelBuilder modelBuilder)
  25. {
  26. modelBuilder.Entity<Employee>(entity =>
  27. {
  28. entity.ToTable("employee");
  29. entity.Property(e => e.Id).HasColumnName("id");
  30. entity.Property(e => e.Birthday)
  31. .HasColumnType("date")
  32. .HasColumnName("birthday");
  33. entity.Property(e => e.Email)
  34. .HasMaxLength(64)
  35. .IsUnicode(false)
  36. .HasColumnName("email");
  37. entity.Property(e => e.Name)
  38. .HasMaxLength(50)
  39. .IsUnicode(false)
  40. .HasColumnName("name");
  41. entity.Property(e => e.Patronymic)
  42. .HasMaxLength(50)
  43. .IsUnicode(false)
  44. .HasColumnName("patronymic");
  45. entity.Property(e => e.Phone)
  46. .HasMaxLength(32)
  47. .IsUnicode(false)
  48. .HasColumnName("phone");
  49. entity.Property(e => e.Surname)
  50. .HasMaxLength(50)
  51. .IsUnicode(false)
  52. .HasColumnName("surname");
  53. entity.Property(e => e.TitleId).HasColumnName("title_id");
  54. entity.HasOne(d => d.Title).WithMany(p => p.Employees)
  55. .HasForeignKey(d => d.TitleId)
  56. .OnDelete(DeleteBehavior.ClientSetNull)
  57. .HasConstraintName("FK_employee_title");
  58. });
  59. modelBuilder.Entity<Title>(entity =>
  60. {
  61. entity.ToTable("title");
  62. entity.Property(e => e.Id).HasColumnName("id");
  63. entity.Property(e => e.Name)
  64. .HasMaxLength(64)
  65. .IsUnicode(false)
  66. .HasColumnName("name");
  67. });
  68. OnModelCreatingPartial(modelBuilder);
  69. }
  70. partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
  71. }