SongListContext.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.EntityFrameworkCore;
  4. using Microsoft.EntityFrameworkCore.Metadata;
  5. namespace MusicAPI.BaseModel
  6. {
  7. public partial class SongListContext : DbContext
  8. {
  9. public SongListContext()
  10. {
  11. }
  12. public SongListContext(DbContextOptions<SongListContext> options)
  13. : base(options)
  14. {
  15. }
  16. public virtual DbSet<Artist> Artists { get; set; } = null!;
  17. public virtual DbSet<Genre> Genres { get; set; } = null!;
  18. public virtual DbSet<Song> Songs { get; set; } = null!;
  19. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  20. {
  21. if (!optionsBuilder.IsConfigured)
  22. {
  23. optionsBuilder.UseSqlServer("Server=sql;Database=SongList;User ID=23П;Password=12357;Trusted_Connection=True;Integrated Security=False;Encrypt=False");
  24. }
  25. }
  26. protected override void OnModelCreating(ModelBuilder modelBuilder)
  27. {
  28. modelBuilder.Entity<Artist>(entity =>
  29. {
  30. entity.HasKey(e => e.IdArtist)
  31. .HasName("PK__Artists__3B155B87C5FDA726");
  32. entity.Property(e => e.IdArtist).HasColumnName("ID_Artist");
  33. entity.Property(e => e.NameArtist)
  34. .IsUnicode(false)
  35. .HasColumnName("Name_Artist");
  36. });
  37. modelBuilder.Entity<Genre>(entity =>
  38. {
  39. entity.HasKey(e => e.IdGenre)
  40. .HasName("PK__Genres__7B31A83B1CB13B02");
  41. entity.Property(e => e.IdGenre).HasColumnName("ID_Genre");
  42. entity.Property(e => e.NameGenre)
  43. .IsUnicode(false)
  44. .HasColumnName("Name_Genre");
  45. });
  46. modelBuilder.Entity<Song>(entity =>
  47. {
  48. entity.HasKey(e => e.IdSong)
  49. .HasName("PK__Songs__EDE8C2894FE8E7DE");
  50. entity.Property(e => e.IdSong).HasColumnName("ID_Song");
  51. entity.Property(e => e.IdArtist).HasColumnName("ID_Artist");
  52. entity.Property(e => e.IdGenre).HasColumnName("ID_Genre");
  53. entity.Property(e => e.NameSong)
  54. .IsUnicode(false)
  55. .HasColumnName("Name_Song");
  56. entity.HasOne(d => d.IdArtistNavigation)
  57. .WithMany(p => p.Songs)
  58. .HasForeignKey(d => d.IdArtist)
  59. .HasConstraintName("FK__Songs__ID_Artist__3C69FB99");
  60. entity.HasOne(d => d.IdGenreNavigation)
  61. .WithMany(p => p.Songs)
  62. .HasForeignKey(d => d.IdGenre)
  63. .HasConstraintName("FK__Songs__ID_Genre__3D5E1FD2");
  64. });
  65. OnModelCreatingPartial(modelBuilder);
  66. }
  67. partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
  68. }
  69. }