ComputerHardwareStore_YouAr.../ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/ComputerHardwareStoreDBContext.cs

40 lines
1.9 KiB
C#
Raw Normal View History

2024-04-29 21:02:41 +04:00
using ComputerHardwareStoreDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace ComputerHardwareStoreDatabaseImplement
{
public class ComputerHardwareStoreDBContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
//optionsBuilder.UseNpgsql(@"Host=localhost;Database=ProductBar_db;Username=postgres;Password=postgres"); // не надо >:
/*
* в program добавить:
* // получаем строку подключения из файла конфигурации
* string connection = builder.Configuration.GetConnectionString("DefaultConnection");
*
* // добавляем контекст ApplicationContext в качестве сервиса в приложение
* builder.Services.AddDbContext<ApplicationContext>(options => options.UseSqlServer(connection));
*
* в appsettings:
* "ConnectionStrings": {
* "DefaultConnection": "Host=localhost;Database=ProductBar_db;Username=compstore;Password=compstore"
* },
*/
}
base.OnConfiguring(optionsBuilder);
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
}
public virtual DbSet<Component> Components { set; get; }
public virtual DbSet<Product> Products { set; get; }
public virtual DbSet<ProductComponent> ProductComponents { set; get; }
2024-04-30 15:57:30 +04:00
public virtual DbSet<StoreKeeper> StoreKeepers { set; get; }
public virtual DbSet<Build> Builds { set; get; }
2024-04-30 17:05:42 +04:00
public virtual DbSet<OrderProduct> OrderProducts { set; get; }
2024-04-29 21:02:41 +04:00
}
}