From 3784108a4e819986648e99e8e493f570396a0adc Mon Sep 17 00:00:00 2001 From: Railz Date: Mon, 30 Sep 2019 14:54:15 +0200 Subject: [PATCH] Fixed init of DbIntermediateForeignObject --- .../Attributes/DbIntermediateForeignObject.cs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Database-Attribute_System/Attributes/DbIntermediateForeignObject.cs b/Database-Attribute_System/Attributes/DbIntermediateForeignObject.cs index c069052..de0bf26 100644 --- a/Database-Attribute_System/Attributes/DbIntermediateForeignObject.cs +++ b/Database-Attribute_System/Attributes/DbIntermediateForeignObject.cs @@ -41,15 +41,12 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System.Attributes this.classAttribute = classAttribute; this.foreignObjectType = fi.FieldType; - // Init foreign-object class - DbObject foreignClassAttribute = ClassAction.Init(this.foreignObjectType); - if (classAttribute.primaryKeyAttributes.Count < 1) throw new InvalidOperationException($"'{classAttribute.parentClassType.Name}' does not have a primaryKey."); if (classAttribute.primaryKeyAttributes.Count > 1) throw new InvalidOperationException($"IntermediateObject does not support multiple primaryKeys."); // Get primaryKey name if none is set if (_keyName == null) _keyName = classAttribute.primaryKeyAttributes[0]._attributeName; - if (!(fi.FieldType is IList && fi.FieldType.IsGenericType)) // 1:m + if (!(fi.FieldType.IsGenericType && (fi.FieldType.GetGenericTypeDefinition() == typeof(List<>)))) // 1:m throw new InvalidOperationException($"IntermediateObject has to be typeof(List). Maybe you meant to use DbForeignObject or DbReverseForeignObject for 1:m or 1:1 relations."); // Check the generic list and get inner-type @@ -66,13 +63,14 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System.Attributes } if (foreignObjectType == null) throw new InvalidOperationException("Could not read innter-type of generic-list!"); - // Now get the primaryKey from my foreignObject - DbObject foreignDbObject = ClassAction.Init(foreignObjectType); + // Init inner-type class + DbObject foreignClassAttribute = ClassAction.Init(foreignObjectType); + // Check the primaryKey/s - if (foreignDbObject.primaryKeyAttributes.Count < 1) throw new InvalidOperationException($"'{foreignDbObject.parentClassType.Name}' does not have a primaryKey."); - if (foreignDbObject.primaryKeyAttributes.Count > 1) throw new InvalidOperationException($"IntermediateObject does not support multiple primaryKeys. (Found '{foreignDbObject.primaryKeyAttributes.Count}' in '{foreignDbObject.parentClassType.Name}')"); + if (foreignClassAttribute.primaryKeyAttributes.Count < 1) throw new InvalidOperationException($"'{foreignClassAttribute.parentClassType.Name}' does not have a primaryKey."); + if (foreignClassAttribute.primaryKeyAttributes.Count > 1) throw new InvalidOperationException($"IntermediateObject does not support multiple primaryKeys. (Found '{foreignClassAttribute.primaryKeyAttributes.Count}' in '{foreignClassAttribute.parentClassType.Name}')"); // Save it - foreignPrimaryKeyAttribute = foreignDbObject.primaryKeyAttributes[0]; + foreignPrimaryKeyAttribute = foreignClassAttribute.primaryKeyAttributes[0]; if (_foreignKeyName == null) _foreignKeyName = foreignPrimaryKeyAttribute._attributeName; }