Connect To CarServiceDataBase

This commit is contained in:
RavilGismatullin 2024-05-05 11:39:21 +03:00
parent 8834d9a288
commit 4321d773e7
5 changed files with 59 additions and 2 deletions

View File

@ -5,6 +5,8 @@ VisualStudioVersion = 17.6.33717.318
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleMainApp", "ConsoleMainApp\ConsoleMainApp.csproj", "{4121A5A1-68DA-4F32-B8D6-EE5BA60C6890}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarServiceDataBaseImplements", "CarServiceDataBaseImplements\CarServiceDataBaseImplements.csproj", "{48D159D4-7150-417E-BBE9-2B636E1EAFFB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{4121A5A1-68DA-4F32-B8D6-EE5BA60C6890}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4121A5A1-68DA-4F32-B8D6-EE5BA60C6890}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4121A5A1-68DA-4F32-B8D6-EE5BA60C6890}.Release|Any CPU.Build.0 = Release|Any CPU
{48D159D4-7150-417E-BBE9-2B636E1EAFFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48D159D4-7150-417E-BBE9-2B636E1EAFFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48D159D4-7150-417E-BBE9-2B636E1EAFFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48D159D4-7150-417E-BBE9-2B636E1EAFFB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarServiceDataBaseImplements
{
public class CarServiceDataBase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if(optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseNpgsql("Host=localhost;Database=CarServiceDataBase;Username=postgres;Password=postgres");
}
base.OnConfiguring(optionsBuilder);
}
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
</ItemGroup>
</Project>

View File

@ -7,4 +7,12 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Npgsql" Version="7.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CarServiceDataBaseImplements\CarServiceDataBaseImplements.csproj" />
</ItemGroup>
</Project>

View File

@ -1,10 +1,17 @@
namespace ConsoleMainApp
using CarServiceDataBaseImplements;
using Microsoft.EntityFrameworkCore;
using Npgsql;
namespace ConsoleMainApp
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
using var context = new CarServiceDataBase();
context.Database.OpenConnection();
context.Database.CloseConnection();
}
}
}