Blagodat/Hardik/Conect/Conector.cs

64 lines
1.8 KiB
C#
Raw Normal View History

2025-05-13 12:33:26 +00:00
using Demka_Snova_1.Hardik.Conect.Dao;
using Microsoft.EntityFrameworkCore;
2025-04-22 07:25:24 +00:00
2025-05-13 12:33:26 +00:00
namespace Demka_Snova_1.Hardik.Conect;
2025-02-11 10:23:14 +00:00
2025-05-13 12:33:26 +00:00
public class AppDbContext : DbContext
{
private readonly string _connectionString;
2025-04-22 07:25:24 +00:00
2025-05-13 12:33:26 +00:00
public AppDbContext(string connectionString)
{
_connectionString = connectionString;
}
2025-02-11 10:23:14 +00:00
2025-05-13 12:33:26 +00:00
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(_connectionString,
sqlOptions => sqlOptions.EnableRetryOnFailure());
}
}
2025-03-05 09:12:58 +00:00
2025-05-13 12:33:26 +00:00
public DbSet<SotrudnikDao> Sotrudnik { get; set; }
public DbSet<uslugiDao> Uslugi { get; set; }
public DbSet<ordersDao> Orders { get; set; }
public DbSet<KlientDao> Klient { get; set; }
public DbSet<historyDao> History { get; set; }
2025-03-05 09:12:58 +00:00
2025-05-13 12:33:26 +00:00
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<KlientDao>(entity =>
{
entity.ToTable("Klient", "Demo_Blago");
entity.HasKey(e => e.Code);
entity.Property(e => e.Code).ValueGeneratedOnAdd();
});
2025-03-05 09:12:58 +00:00
2025-05-13 12:33:26 +00:00
modelBuilder.Entity<ordersDao>(entity =>
{
entity.ToTable("orders", "Demo_Blago");
entity.HasKey(e => e.ID);
entity.Property(e => e.ID).ValueGeneratedOnAdd();
});
2025-03-05 09:12:58 +00:00
2025-05-13 12:33:26 +00:00
modelBuilder.Entity<uslugiDao>(entity =>
{
entity.ToTable("uslugi", "Demo_Blago");
entity.HasKey(e => e.id);
});
modelBuilder.Entity<SotrudnikDao>(entity =>
{
entity.ToTable("Sotrudnik", "Demo_Blago");
entity.HasKey(e => e.ID);
});
modelBuilder.Entity<historyDao>(entity =>
{
entity.ToTable("history", "Demo_Blago");
entity.HasKey(e => e.id);
});
}
}