ISMS_YcContext.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using CodeFirstExistingDatabaseSample.ISMS_Yc.Models;
  4. using Microsoft.EntityFrameworkCore;
  5. using Microsoft.EntityFrameworkCore.Metadata;
  6. namespace CodeFirstExistingDatabaseSample
  7. {
  8. public partial class ISMS_YcContext : DbContext
  9. {
  10. public ISMS_YcContext()
  11. {
  12. }
  13. public ISMS_YcContext(DbContextOptions<ISMS_YcContext> options)
  14. : base(options)
  15. {
  16. }
  17. public virtual DbSet<ImYcdata20001031> ImYcdata20001031s { get; set; } = null!;
  18. public virtual DbSet<ImYcdata20240722> ImYcdata20240722s { get; set; } = null!;
  19. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  20. {
  21. if (!optionsBuilder.IsConfigured)
  22. {
  23. #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.
  24. optionsBuilder.UseSqlServer("Server=192.168.110.161;User ID=sa;Password=sa;Database=ISMS_Yc;Trusted_Connection=False;");
  25. }
  26. }
  27. protected override void OnModelCreating(ModelBuilder modelBuilder)
  28. {
  29. modelBuilder.Entity<ImYcdata20001031>(entity =>
  30. {
  31. entity.HasKey(e => new { e.DataId, e.OccTime });
  32. entity.ToTable("im_YCData20001031");
  33. entity.HasIndex(e => e.OccTime, "Ind_im_YCData20001031");
  34. entity.Property(e => e.DataId)
  35. .HasMaxLength(12)
  36. .IsUnicode(false)
  37. .HasColumnName("DataID");
  38. entity.Property(e => e.OccTime).HasColumnType("datetime");
  39. entity.Property(e => e.SeqNo).ValueGeneratedOnAdd();
  40. entity.Property(e => e.TimeSrc)
  41. .HasMaxLength(8)
  42. .IsUnicode(false);
  43. });
  44. modelBuilder.Entity<ImYcdata20240722>(entity =>
  45. {
  46. entity.HasKey(e => new { e.DataId, e.OccTime });
  47. entity.ToTable("im_YCData20240722");
  48. entity.HasIndex(e => e.OccTime, "Ind_im_YCData20240722");
  49. entity.Property(e => e.DataId)
  50. .HasMaxLength(12)
  51. .IsUnicode(false)
  52. .HasColumnName("DataID");
  53. entity.Property(e => e.OccTime).HasColumnType("datetime");
  54. entity.Property(e => e.SeqNo).ValueGeneratedOnAdd();
  55. entity.Property(e => e.TimeSrc)
  56. .HasMaxLength(8)
  57. .IsUnicode(false);
  58. });
  59. OnModelCreatingPartial(modelBuilder);
  60. }
  61. partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
  62. }
  63. }