/// Marks variable as reverse-foreign-object of an dbObject
/// </summary>
/// <param name="foreignKeyName">Fieldname of primaryKey associated with the reverseForeignObject (null if same as primary key) [Only works with 1 primaryKey]</param>
if(classAttribute.primaryKeyAttributes.Count<1)thrownewInvalidOperationException($"'{classAttribute.parentClassType.Name}' does not have a primaryKey.");
if(classAttribute.primaryKeyAttributes.Count>1)thrownewInvalidOperationException($"ReverseForeignObject does not support multiple primaryKeys.");
if(primaryKey._attributeName.ToLower()==foreignKey._attributeName.ToLower())// Name matches
if(primaryKey.parentField.GetType()==foreignKey.parentField.GetType())// Type matches
{
foreignKeyAttribute=foreignKey;
}
else
// Same name, but wrong type
thrownewInvalidOperationException($"ForeignObject='{foreignClassAttribute.parentClassType.Name}' has invalid type foreignKey='{foreignKey.parentField.Name}' for object='{classAttribute.parentClassType.Name}' with primaryKey='{primaryKey.parentField.Name}'.");
}
// No match
if(foreignKeyAttribute==null)thrownewInvalidOperationException($"ForeignObject='{foreignClassAttribute.parentClassType.Name}' is missing foreignKey for object='{classAttribute.parentClassType.Name}' with primaryKey='{primaryKey.parentField.Name}'.");
if(!dataMatchFound)thrownewInvalidOperationException($"Cannot create object with primaryKeyData. No data assigned to field '{primaryKeyAtt.parentField.Name}'");
if(!dataMatchFound)thrownewInvalidOperationException($"PrimaryKey='{primaryKeyAtt.parentField.Name}' is missing.");
if(values.Count==0)thrownewInvalidOperationException($"'{reverseForeignObjectAtt.parentField.Name}' could not been resolved. ReverseForeignObject returned '{values.Count}' values.");
if(reverseForeignObject_typeisIList&&reverseForeignObject_type.IsGenericType)// List, so 1:m
{
reverseForeignObject_value=values;
}
else// Not list, so 1:1
{
if(values.Count>1)thrownewInvalidOperationException($"'{reverseForeignObjectAtt.parentField.Name}' could not been resolved as ReverseForeignObject returned '{values.Count}' values. (Is it 1:1 instead of 1:m?)");