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.");