From b8218fbacd32877a2c5c5851b7d3fcd15581db08 Mon Sep 17 00:00:00 2001 From: Alexander B Date: Fri, 12 Apr 2019 13:35:18 +0200 Subject: [PATCH] Added InsertAttributesByObject --- Database-Attribute_System/QueryBuilder.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Database-Attribute_System/QueryBuilder.cs b/Database-Attribute_System/QueryBuilder.cs index 76d9345..315a169 100644 --- a/Database-Attribute_System/QueryBuilder.cs +++ b/Database-Attribute_System/QueryBuilder.cs @@ -138,6 +138,29 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System return BuildQuery(param); } + /// + /// Builds an INSERT-Sql-query based on an object + /// + /// + /// + /// + public static string InsertAttributesByObject(T classObject) + { + Type classType = classObject.GetType(); + + // Read dbObject-attribute + DbObject dbObject = ClassAction.Init(classType); + + List attributes = new List() { }; + List data = new List() { }; + foreach(BaseAttribute baseAttribute in dbObject.baseAttributes) + { + attributes.Add(baseAttribute._attributeName); + data.Add(baseAttribute.parentField.GetValue(classObject)); + } + + return InsertAttributes(dbObject._tableName, attributes, data); + } public static string InsertAttributes(string tableName, Dictionary dbAttributes) { if (dbAttributes.Count == 0) throw new InvalidOperationException("Cannot generate SQL-Query. No attributes to insert.");