From e050983f7c7c601d9dad79fe3e6a693cb2c2da0c Mon Sep 17 00:00:00 2001 From: Damian Wessels Date: Fri, 14 Apr 2023 09:16:46 +0200 Subject: [PATCH] datenbank referenzen geupdated --- .../PostgresqlData/AuftraggeberDataService.cs | 8 ++++---- .../PostgresqlData/HaltungDataService.cs | 20 +++++++++---------- .../PostgresqlData/PostgresqlDataService.cs | 2 +- .../PostgresqlData/ProjektDataService.cs | 10 +++++----- .../PostgresqlData/SchachtDataService.cs | 11 +++++----- 5 files changed, 25 insertions(+), 26 deletions(-) diff --git a/SewerStammGen.DAL/Services/PostgresqlData/AuftraggeberDataService.cs b/SewerStammGen.DAL/Services/PostgresqlData/AuftraggeberDataService.cs index f101ff9..5d4823c 100644 --- a/SewerStammGen.DAL/Services/PostgresqlData/AuftraggeberDataService.cs +++ b/SewerStammGen.DAL/Services/PostgresqlData/AuftraggeberDataService.cs @@ -11,12 +11,12 @@ namespace SewerStammGen.DAL.Services.PostgresqlData { public class AuftraggeberDataService : PostgresqlDataService, IAuftraggeberDataService { - public AuftraggeberDataService(string connectionstring) : base(connectionstring,"Auftraggebers") { } + public AuftraggeberDataService(string connectionstring) : base(connectionstring,"auftraggeber") { } public async Task Create(Auftraggeber entity) { - string command = "INSERT INTO "+tableName+" (\"Name\", \"Strasse\", \"Ort\", \"Postleitzahl\", \"Ansprechpartner\", \"Telefonnummer\") " + - "VALUES(@1,@2,@3,@4,@5,@6) RETURNING \"Id\""; + string command = "INSERT INTO "+tableName+" (name, strasse, ort, postleitzahl, ansprechpartner, telefonnummer) " + + "VALUES(@1,@2,@3,@4,@5,@6) RETURNING auftraggeber_id"; await using (var cmd = new NpgsqlCommand(command, conn)) { @@ -37,7 +37,7 @@ namespace SewerStammGen.DAL.Services.PostgresqlData public async Task Get(int id) { Auftraggeber result = new Auftraggeber(); - using (var cmd = new NpgsqlCommand($"SELECT * FROM "+tableName+" WHERE \"Id\" = @1", conn)) + using (var cmd = new NpgsqlCommand($"SELECT * FROM "+tableName+" WHERE auftraggeber_id = @1", conn)) { cmd.Parameters.AddWithValue("1", id); using var reader = await cmd.ExecuteReaderAsync(); diff --git a/SewerStammGen.DAL/Services/PostgresqlData/HaltungDataService.cs b/SewerStammGen.DAL/Services/PostgresqlData/HaltungDataService.cs index 8112eee..06642d1 100644 --- a/SewerStammGen.DAL/Services/PostgresqlData/HaltungDataService.cs +++ b/SewerStammGen.DAL/Services/PostgresqlData/HaltungDataService.cs @@ -12,7 +12,7 @@ namespace SewerStammGen.DAL.Services.PostgresqlData { public class HaltungDataService : PostgresqlDataService, IHaltungDataService { - public HaltungDataService(string connectionstring) : base(connectionstring, "Kanaele") + public HaltungDataService(string connectionstring) : base(connectionstring, "haltung") { } @@ -37,7 +37,7 @@ namespace SewerStammGen.DAL.Services.PostgresqlData ISchachtDataService schachtDataService = new SchachtDataService(connString); IEnumerable schaechte = await schachtDataService.GetAllByProjekt(projektID); - string command = "SELECT * FROM " + tableName + " WHERE \"ProjektId\" = @1"; + string command = "SELECT * FROM " + tableName + " WHERE ref_projekt_id = @1"; using (var cmd = new NpgsqlCommand(command, conn)) { cmd.Parameters.AddWithValue("1", projektID); @@ -82,14 +82,14 @@ namespace SewerStammGen.DAL.Services.PostgresqlData { string command = "UPDATE " + tableName + " SET " + - " \"Objektbezeichnung\"=@1, " + - " \"StartSchachtId\"=@2, " + - " \"EndSchachtId\"=@3, " + - " \"DN\"=@4, " + - " \"Material\"=@5, " + - " \"Haltungslaenge\"=@6, " + - " \"Entwaesserung\"=@7 " + - " WHERE \"Id\" = @8"; + " objektbezeichnung=@1, " + + " ref_startschacht_id=@2, " + + " ref_endschacht_id=@3, " + + " dn=@4, " + + " material=@5, " + + " haltungslaenge=@6, " + + " entwaesserung=@7 " + + " WHERE haltung_id = @8"; using(var cmd = new NpgsqlCommand(command,conn)) { cmd.Parameters.AddWithValue("1", entity.Objektbezeichnung); diff --git a/SewerStammGen.DAL/Services/PostgresqlData/PostgresqlDataService.cs b/SewerStammGen.DAL/Services/PostgresqlData/PostgresqlDataService.cs index 2459174..b30f366 100644 --- a/SewerStammGen.DAL/Services/PostgresqlData/PostgresqlDataService.cs +++ b/SewerStammGen.DAL/Services/PostgresqlData/PostgresqlDataService.cs @@ -22,7 +22,7 @@ namespace SewerStammGen.DAL.Services.PostgresqlData dataSource = dataSourceBuilder.Build(); conn = dataSource.OpenConnection(); - this.tableName = string.Format("public.\"{0}\"", tableName); + this.tableName = string.Format("public.{0}", tableName); } diff --git a/SewerStammGen.DAL/Services/PostgresqlData/ProjektDataService.cs b/SewerStammGen.DAL/Services/PostgresqlData/ProjektDataService.cs index 003f4fa..10a48dc 100644 --- a/SewerStammGen.DAL/Services/PostgresqlData/ProjektDataService.cs +++ b/SewerStammGen.DAL/Services/PostgresqlData/ProjektDataService.cs @@ -14,15 +14,15 @@ namespace SewerStammGen.DAL.Services.PostgresqlData { public class ProjektDataService : PostgresqlDataService, IProjektDataService { - public ProjektDataService(string connectionstring) : base(connectionstring,"Projekte") + public ProjektDataService(string connectionstring) : base(connectionstring,"projekt") { } public async Task Create(Projekt entity) { - string command = "INSERT INTO "+tableName+" (\"Projektname\", \"Erstelldatum\", \"Strasse\", \"Ort\", \"ExportType\", \"Kodierungssystem\",\"AuftraggeberId\") " + - "VALUES(@1,@2,@3,@4,@5,@6,@7) RETURNING \"Id\""; + string command = "INSERT INTO "+tableName+" (projektname, erstelldatum, strasse, ort, exporttype, kodierungssystem,ref_auftraggeber_id) " + + "VALUES(@1,@2,@3,@4,@5,@6,@7) RETURNING projekt_id"; if (entity.Auftraggeber.Id == 0) { @@ -52,7 +52,7 @@ namespace SewerStammGen.DAL.Services.PostgresqlData { Projekt result = new Projekt(); IAuftraggeberDataService auftraggeberDataService = new AuftraggeberDataService(connString); - using (var cmd = new NpgsqlCommand($"SELECT * FROM "+tableName+" WHERE \"Id\" = @1", conn)) + using (var cmd = new NpgsqlCommand($"SELECT * FROM "+tableName+" WHERE projekt_id = @1", conn)) { cmd.Parameters.AddWithValue("1", id); using var reader = await cmd.ExecuteReaderAsync(); @@ -99,7 +99,7 @@ namespace SewerStammGen.DAL.Services.PostgresqlData public async Task Update(Projekt entity) { - string command = "UPDATE "+tableName+" SET \"Projektname\"=@1, \"Erstelldatum\"=@2, \"Strasse\"=@3, \"Ort\"=@4, \"ExportType\"=@5, \"Kodierungssystem\"=@6 WHERE \"Id\" = @8"; + string command = "UPDATE "+tableName+" SET projektname=@1, erstelldatum=@2, strasse=@3, ort=@4, exporttype=@5, kodierungssystem=@6 WHERE projekt_id = @8"; using (var cmd = new NpgsqlCommand(command, conn)) { cmd.Parameters.AddWithValue("1", entity.Projektname); diff --git a/SewerStammGen.DAL/Services/PostgresqlData/SchachtDataService.cs b/SewerStammGen.DAL/Services/PostgresqlData/SchachtDataService.cs index 689c5e8..40036b7 100644 --- a/SewerStammGen.DAL/Services/PostgresqlData/SchachtDataService.cs +++ b/SewerStammGen.DAL/Services/PostgresqlData/SchachtDataService.cs @@ -11,13 +11,13 @@ namespace SewerStammGen.DAL.Services.PostgresqlData { public class SchachtDataService : PostgresqlDataService, ISchachtDataService { - public SchachtDataService(string connectionstring) : base(connectionstring,"Schaechte") + public SchachtDataService(string connectionstring) : base(connectionstring,"schacht") { } public async Task Create(Schacht entity) { - string command = "INSERT INTO " + tableName + " (\"Objektbezeichnung\",\"RechtsWert\",\"HochWert\",\"SohlHoehe\",\"DeckelHoehe\",\"Entwaesserung\",\"ProjektId\") VALUES " + + string command = "INSERT INTO " + tableName + " (objektbezeichnung,rechtswert,hochwert,sohlhoehe,deckelhoehe,entwaesserung,ref_projekt_id) VALUES " + "(@1,@2,@3,@4,@5,@6,@7) RETURNING \"Id\""; using(var cmd = new NpgsqlCommand(command,conn)) { @@ -63,7 +63,7 @@ namespace SewerStammGen.DAL.Services.PostgresqlData public async Task> GetAllByProjekt(int projektID) { List result = new List(); - string command = @"SELECT * FROM " + tableName + " WHERE \"ProjektId\" = @1"; + string command = @"SELECT * FROM " + tableName + " WHERE ref_projekt_id = @1"; using (var cmd = new NpgsqlCommand(command, conn)) { cmd.Parameters.AddWithValue("1", projektID); @@ -86,9 +86,8 @@ namespace SewerStammGen.DAL.Services.PostgresqlData public async Task Update(Schacht entity) { - string command = @"UPDATE " + tableName + "SET \"Objektbezeichnung\" =@1, \"RechtsWert\"=@2," + - " \"HochWert\"=@3, \"SohlHoehe\"=@4, \"DeckelHoehe\"=@5, \"Entwaesserung\"=@6," + - " \"ProjektId\"=@7 WHERE \"Id\"=@8"; + string command = @"UPDATE " + tableName + "SET " + + "objektbezeichnung=@1, rechtswert=@2, hochwert=@3, sohlhoehe=@4, deckelhoehe=@5, entwaesserung=@6, ref_projekt_id=@7 WHERE schacht_id=@8"; using(var cmd = new NpgsqlCommand(command,conn)) { cmd.Parameters.AddWithValue("1", entity.Objektbezeichnung);