From ad3c1da0cda85444ef5f3164ddb19e410381d40a Mon Sep 17 00:00:00 2001 From: Railz Date: Wed, 8 May 2019 23:22:20 +0200 Subject: [PATCH] Fixes: - Fields not matching - FieldType being lookedUp wrong - dictionary-access-violation - guid saved as string not casting - InsertQuery built wrong --- Database-Attribute_System/Attributes/DbForeignObject.cs | 4 ++-- Database-Attribute_System/ClassAction.cs | 5 ++++- Database-Attribute_System/QueryBuilder.cs | 8 ++++---- Database-Attribute_System/internal/Function.cs | 5 ++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Database-Attribute_System/Attributes/DbForeignObject.cs b/Database-Attribute_System/Attributes/DbForeignObject.cs index dd058f7..6c79df0 100644 --- a/Database-Attribute_System/Attributes/DbForeignObject.cs +++ b/Database-Attribute_System/Attributes/DbForeignObject.cs @@ -30,7 +30,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System.Attributes { this.parentField = fi; this.classAttribute = classAttribute; - this.foreignObjectType = fi.GetType(); + this.foreignObjectType = fi.FieldType; // Init foreign-object class DbObject foreignClassAttribute = ClassAction.Init(this.foreignObjectType); @@ -45,7 +45,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System.Attributes if(this._foreignKeyName != null) // If i have a name { // check if name matches - if (foreignKey.parentField.Name.ToLower() == this._foreignKeyName) + if (foreignKey.parentField.Name.ToLower() == this._foreignKeyName.ToLower()) { if(foreignKey.parentField.GetType() == primaryKeyType) { diff --git a/Database-Attribute_System/ClassAction.cs b/Database-Attribute_System/ClassAction.cs index 0775e81..308c7bd 100644 --- a/Database-Attribute_System/ClassAction.cs +++ b/Database-Attribute_System/ClassAction.cs @@ -60,7 +60,10 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System // If its a match, set the value if (baseAttribute._attributeName.ToLower() == data_keySet.Key.ToLower()) { - baseAttribute.parentField.SetValue(classObject, data_keySet.Value); + object value = data_keySet.Value; + if (baseAttribute.parentField.FieldType == typeof(Guid)) value = new Guid((string)value); // If its a guid, i need to convert + + baseAttribute.parentField.SetValue(classObject, value); break; } } diff --git a/Database-Attribute_System/QueryBuilder.cs b/Database-Attribute_System/QueryBuilder.cs index 315a169..d056b97 100644 --- a/Database-Attribute_System/QueryBuilder.cs +++ b/Database-Attribute_System/QueryBuilder.cs @@ -181,14 +181,14 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System if (attributes.Count != data.Count) throw new InvalidOperationException("Cannot generate SQL-Query. Attribute-count and data-count not equal."); string attributesSeperatedByComma = ""; - object[] attributeData = new object[attributes.Count*2]; + object[] attributeData = new object[attributes.Count*2 -1]; int c = 0; - for(int i=0; i convertedAttributeNameAndValues = new Dictionary(); foreach (KeyValuePair attributeNameAndValue in attributeNameAndValues) { @@ -87,9 +88,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System { if (attributeNameAndValue.Key.ToLower() == baseAttribute.parentField.Name.ToLower()) { - attributeNameAndValues.Remove(attributeNameAndValue.Key); - - attributeNameAndValues.Add(baseAttribute._attributeName, attributeNameAndValue.Value); + convertedAttributeNameAndValues.Add(baseAttribute._attributeName, attributeNameAndValue.Value); nameFound = true; break;