FillObject: Check if keys are Dbnull, so not set

ResolveForeignKeys: Check if key is set
master v1.5.23
Railz 5 years ago
parent ef73a51ab5
commit 7e56187733

@ -69,11 +69,17 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
if (baseAttribute._attributeName.ToLower() == data_keySet.Key.ToLower())
{
object value = data_keySet.Value;
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;
}
}
}
}
}
@ -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<T>(foreignObjectAtt.foreignObjectType, foreignObjectAtt.foreignKeyAttribute.parentField.GetValue(classObject), queryExecutor);
foreignObject_value = GetByPrimaryKey<T>(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

Loading…
Cancel
Save