AstashinApiContext.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace API.BaseModel;
  5. public partial class AstashinApiContext : DbContext
  6. {
  7. public AstashinApiContext()
  8. {
  9. }
  10. public AstashinApiContext(DbContextOptions<AstashinApiContext> options)
  11. : base(options)
  12. {
  13. }
  14. public virtual DbSet<Auto> Autos { get; set; }
  15. public virtual DbSet<CarBody> CarBodies { get; set; }
  16. public virtual DbSet<Price> Prices { get; set; }
  17. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  18. #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.
  19. => optionsBuilder.UseSqlServer("Server=sql;Database=AstashinApi;User ID=23П;Password=12357;Trusted_Connection=True;Integrated Security=False;Encrypt=False");
  20. protected override void OnModelCreating(ModelBuilder modelBuilder)
  21. {
  22. modelBuilder.Entity<Auto>(entity =>
  23. {
  24. entity.HasKey(e => e.IdAuto);
  25. entity.ToTable("Auto");
  26. entity.Property(e => e.IdAuto).HasColumnName("id_auto");
  27. entity.Property(e => e.Brand)
  28. .HasMaxLength(50)
  29. .IsUnicode(false);
  30. entity.Property(e => e.Color)
  31. .HasMaxLength(50)
  32. .IsUnicode(false);
  33. entity.Property(e => e.IdCarBody).HasColumnName("id_car_body");
  34. entity.Property(e => e.IdPrice).HasColumnName("id_price");
  35. entity.Property(e => e.Model)
  36. .HasMaxLength(50)
  37. .IsUnicode(false);
  38. entity.HasOne(d => d.IdCarBodyNavigation).WithMany(p => p.Autos)
  39. .HasForeignKey(d => d.IdCarBody)
  40. .HasConstraintName("FK_Auto_Car_body");
  41. entity.HasOne(d => d.IdPriceNavigation).WithMany(p => p.Autos)
  42. .HasForeignKey(d => d.IdPrice)
  43. .HasConstraintName("FK_Auto_Price");
  44. });
  45. modelBuilder.Entity<CarBody>(entity =>
  46. {
  47. entity.HasKey(e => e.IdCarBody);
  48. entity.ToTable("Car_body");
  49. entity.Property(e => e.IdCarBody).HasColumnName("id_car_body");
  50. entity.Property(e => e.CarBody1)
  51. .HasMaxLength(50)
  52. .IsUnicode(false)
  53. .HasColumnName("Car_body");
  54. });
  55. modelBuilder.Entity<Price>(entity =>
  56. {
  57. entity.HasKey(e => e.IdPrice).HasName("PK_Table_1");
  58. entity.ToTable("Price");
  59. entity.Property(e => e.IdPrice).HasColumnName("id_price");
  60. entity.Property(e => e.Price1).HasColumnName("Price");
  61. });
  62. OnModelCreatingPartial(modelBuilder);
  63. }
  64. partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
  65. }