InvestContext.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #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.
  18. => optionsBuilder.UseSqlServer("Data Source=srv-wsr\\is3;Initial Catalog=invest;User ID=user12;Password=user12;Encrypt=False");
  19. protected override void OnModelCreating(ModelBuilder modelBuilder)
  20. {
  21. modelBuilder.Entity<Employee>(entity =>
  22. {
  23. entity.ToTable("employee");
  24. entity.Property(e => e.Id).HasColumnName("id");
  25. entity.Property(e => e.Birthday)
  26. .HasColumnType("date")
  27. .HasColumnName("birthday");
  28. entity.Property(e => e.Email)
  29. .HasMaxLength(64)
  30. .IsUnicode(false)
  31. .HasColumnName("email");
  32. entity.Property(e => e.Name)
  33. .HasMaxLength(50)
  34. .IsUnicode(false)
  35. .HasColumnName("name");
  36. entity.Property(e => e.Patronymic)
  37. .HasMaxLength(50)
  38. .IsUnicode(false)
  39. .HasColumnName("patronymic");
  40. entity.Property(e => e.Phone)
  41. .HasMaxLength(32)
  42. .IsUnicode(false)
  43. .HasColumnName("phone");
  44. entity.Property(e => e.Surname)
  45. .HasMaxLength(50)
  46. .IsUnicode(false)
  47. .HasColumnName("surname");
  48. entity.Property(e => e.TitleId).HasColumnName("title_id");
  49. entity.HasOne(d => d.Title).WithMany(p => p.Employees)
  50. .HasForeignKey(d => d.TitleId)
  51. .OnDelete(DeleteBehavior.ClientSetNull)
  52. .HasConstraintName("FK_employee_title");
  53. });
  54. modelBuilder.Entity<Title>(entity =>
  55. {
  56. entity.ToTable("title");
  57. entity.Property(e => e.Id).HasColumnName("id");
  58. entity.Property(e => e.Name)
  59. .HasMaxLength(64)
  60. .IsUnicode(false)
  61. .HasColumnName("name");
  62. });
  63. OnModelCreatingPartial(modelBuilder);
  64. }
  65. partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
  66. }