Fixed Init stackOverFlowException for recursive objects

master
Railz 5 years ago
parent d86e231bda
commit ef73a51ab5

@ -26,14 +26,15 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System.Attributes
this._foreignKeyName = foreignKeyName;
}
public void Init(FieldInfo fi, DbObject classAttribute)
public void Init(FieldInfo fi, DbObject classAttribute, DbObject foreignClassAttribute = null)
{
this.parentField = fi;
this.classAttribute = classAttribute;
this.foreignObjectType = fi.FieldType;
// Init foreign-object class
DbObject foreignClassAttribute = ClassAction.Init(this.foreignObjectType);
if(foreignClassAttribute == null)
foreignClassAttribute = ClassAction.Init(this.foreignObjectType);
// Check if something is weird
if (foreignClassAttribute.primaryKeyAttributes.Count < 1) throw new InvalidOperationException($"'{foreignClassAttribute.parentClassType.Name}' does not have a primaryKey.");

@ -69,6 +69,9 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System.Attributes
}
else if (fi.GetCustomAttribute(typeof(DbForeignObject), true) is DbForeignObject fobj) // ForeignObjects
{
if(fi.FieldType == this.parentClassType) // Check if we are referencing ourselfes
fobj.Init(fi, this, this);
else
fobj.Init(fi, this);
this.foreignObjectAttributes.Add(fobj);

Loading…
Cancel
Save