фиг знает

This commit is contained in:
bekodeg 2024-04-29 21:02:41 +04:00
parent affb89bb59
commit 070473b0d6
3 changed files with 60 additions and 0 deletions

View File

@ -6,6 +6,12 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="BusinessLogic\**" />
<EmbeddedResource Remove="BusinessLogic\**" />
<None Remove="BusinessLogic\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
</ItemGroup>

View File

@ -0,0 +1,35 @@
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; }
}
}

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ComputerHardwareStoreContracts\ComputerHardwareStoreContracts.csproj" />
<ProjectReference Include="..\ComputerHardwareStoreDataModels\ComputerHardwareStoreDataModels.csproj" />
</ItemGroup>
</Project>