From 9c00ec5694bfcb47387d51a8ee2f72a67e3f51b8 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Tue, 25 Apr 2023 23:04:04 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=20=D0=BD=D1=83=20=D0=B2=D1=80?= =?UTF-8?q?=D0=BE=D0=B4=D0=B5=20=D0=B4=D0=B0=D0=B6=D0=B5=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82=20:)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TransportCompany/TransportCompany/App.config | 6 ++++++ .../TransportCompanyDatabaseImplements/ElegevContext.cs | 7 ++++++- .../TransportCompanyDatabaseImplements.csproj | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 TransportCompany/TransportCompany/App.config diff --git a/TransportCompany/TransportCompany/App.config b/TransportCompany/TransportCompany/App.config new file mode 100644 index 0000000..3cd7446 --- /dev/null +++ b/TransportCompany/TransportCompany/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/TransportCompany/TransportCompanyDatabaseImplements/ElegevContext.cs b/TransportCompany/TransportCompanyDatabaseImplements/ElegevContext.cs index ec57a2c..e1cfe71 100644 --- a/TransportCompany/TransportCompanyDatabaseImplements/ElegevContext.cs +++ b/TransportCompany/TransportCompanyDatabaseImplements/ElegevContext.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; +using System.Configuration; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using Microsoft.Extensions.Options; using TransportCompanyDatabaseImplements.Models; namespace TransportCompanyDatabaseImplements; @@ -26,9 +29,11 @@ public partial class ElegevContext : DbContext public virtual DbSet TypeTransportations { get; set; } + string dbName = ConfigurationManager.AppSettings["connectToDb"]; + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) #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. - => optionsBuilder.UseNpgsql("Host=192.168.56.101;Port=6000;Database=elegev;Username=elegev;Password=user"); + => optionsBuilder.UseNpgsql(dbName); protected override void OnModelCreating(ModelBuilder modelBuilder) { diff --git a/TransportCompany/TransportCompanyDatabaseImplements/TransportCompanyDatabaseImplements.csproj b/TransportCompany/TransportCompanyDatabaseImplements/TransportCompanyDatabaseImplements.csproj index 07207df..d58e65a 100644 --- a/TransportCompany/TransportCompanyDatabaseImplements/TransportCompanyDatabaseImplements.csproj +++ b/TransportCompany/TransportCompanyDatabaseImplements/TransportCompanyDatabaseImplements.csproj @@ -16,6 +16,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive +