PersonDBContext.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.EntityFrameworkCore;
  4. using Microsoft.EntityFrameworkCore.Metadata;
  5. namespace HallOfFame
  6. {
  7. public partial class PersonDBContext : DbContext
  8. {
  9. public PersonDBContext()
  10. {
  11. }
  12. public PersonDBContext(DbContextOptions<PersonDBContext> options)
  13. : base(options)
  14. {
  15. }
  16. public virtual DbSet<ConPersonSkill> ConPersonSkills { get; set; } = null!;
  17. public virtual DbSet<Person> Persons { get; set; } = null!;
  18. public virtual DbSet<Skill> Skills { get; set; } = null!;
  19. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  20. {
  21. if (!optionsBuilder.IsConfigured)
  22. {
  23. optionsBuilder.UseSqlServer("Server=localhost;Database=PersonDB;Trusted_Connection=True;");
  24. }
  25. }
  26. protected override void OnModelCreating(ModelBuilder modelBuilder)
  27. {
  28. modelBuilder.Entity<ConPersonSkill>(entity =>
  29. {
  30. entity.HasKey(e => e.IdPersonSkill);
  31. entity.HasIndex(e => e.PersonId, "IX_ConPersonSkills_PersonId");
  32. entity.HasIndex(e => e.SkillId, "IX_ConPersonSkills_SkillId");
  33. entity.HasOne(d => d.Person)
  34. .WithMany(p => p.ConPersonSkills)
  35. .HasForeignKey(d => d.PersonId)
  36. .OnDelete(DeleteBehavior.ClientSetNull)
  37. .HasConstraintName("FK_ConPersonSkills_Persons");
  38. entity.HasOne(d => d.Skill)
  39. .WithMany(p => p.ConPersonSkills)
  40. .HasForeignKey(d => d.SkillId)
  41. .OnDelete(DeleteBehavior.ClientSetNull)
  42. .HasConstraintName("FK_ConPersonSkills_Skills");
  43. });
  44. OnModelCreatingPartial(modelBuilder);
  45. }
  46. partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
  47. }
  48. }