From 7e56187733893a11ca90f81bd4cc14ecb89b17e3 Mon Sep 17 00:00:00 2001 From: Railz Date: Mon, 30 Sep 2019 13:00:39 +0200 Subject: [PATCH] FillObject: Check if keys are Dbnull, so not set ResolveForeignKeys: Check if key is set --- Database-Attribute_System/ClassAction.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Database-Attribute_System/ClassAction.cs b/Database-Attribute_System/ClassAction.cs index fb11352..cdb3e3f 100644 --- a/Database-Attribute_System/ClassAction.cs +++ b/Database-Attribute_System/ClassAction.cs @@ -69,10 +69,16 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System if (baseAttribute._attributeName.ToLower() == data_keySet.Key.ToLower()) { object value = data_keySet.Value; - //if (baseAttribute.parentField.FieldType == typeof(Guid)) value = new Guid((string)value); // If its a guid, i need to convert + if (!(value is DBNull)) // Check if value is empty + { + //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; + } + + - baseAttribute.parentField.SetValue(classObject, value); - break; } } } @@ -295,13 +301,14 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System // Resolve foreignObjects foreach (DbForeignObject foreignObjectAtt in dbObject.foreignObjectAttributes) { + object foreignKey_value = foreignObjectAtt.foreignKeyAttribute.parentField.GetValue(classObject); object foreignObject_value = foreignObjectAtt.parentField.GetValue(classObject); - // When its empty, get it & set it - if(foreignObject_value == null) + // When key is set and object is empty, get it & set it + if(foreignKey_value != null && foreignObject_value == null) { // Resolve it - foreignObject_value = GetByPrimaryKey(foreignObjectAtt.foreignObjectType, foreignObjectAtt.foreignKeyAttribute.parentField.GetValue(classObject), queryExecutor); + foreignObject_value = GetByPrimaryKey(foreignObjectAtt.foreignObjectType, foreignKey_value, queryExecutor); foreignObjectAtt.parentField.SetValue(classObject, foreignObject_value); // Set the value // Now scan the just resolved class to be able to set myself