Fixed ResolveForeignKeys:
Changed generic creation to reflective generation of new object Fixed loading himself
This commit is contained in:
parent
178c92383b
commit
d86e231bda
@ -13,6 +13,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System.Attributes
|
||||
public string _tableName;
|
||||
|
||||
public Type parentClassType;
|
||||
public ConstructorInfo parentCInfo;
|
||||
|
||||
// All childrenAttributes
|
||||
public List<BaseAttribute> baseAttributes = new List<BaseAttribute>() { };
|
||||
@ -35,6 +36,8 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System.Attributes
|
||||
public void Init(Type classType)
|
||||
{
|
||||
this.parentClassType = classType;
|
||||
parentCInfo = classType.GetConstructor(Type.EmptyTypes);
|
||||
|
||||
this._tableName = this._tableName ?? classType.Name; // If no alternative table-name is specified, use the class-name
|
||||
|
||||
// Iterate thru all fields
|
||||
|
@ -104,14 +104,14 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
|
||||
}
|
||||
public static T GetByPrimaryKey<T>(Type classType, Dictionary<string, object> primaryKeyData, Func<string, List<Dictionary<string, object>>> queryExecutor) where T: new()
|
||||
{
|
||||
// Create new empty object
|
||||
T obj = new T();
|
||||
|
||||
// Read dbObject-attribute
|
||||
DbObject dbObject = ClassAction.Init(classType);
|
||||
|
||||
if (dbObject.primaryKeyAttributes.Count < 1) throw new InvalidOperationException($"No primaryKey found in '{classType.Name}'");
|
||||
|
||||
// Create new empty object
|
||||
T obj = (T)dbObject.parentCInfo.Invoke(null);
|
||||
|
||||
// iterate thru them to check and fill object
|
||||
foreach (DbPrimaryKey primaryKeyAtt in dbObject.primaryKeyAttributes)
|
||||
{
|
||||
@ -301,7 +301,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
|
||||
if(foreignObject_value == null)
|
||||
{
|
||||
// Resolve it
|
||||
foreignObject_value = GetByPrimaryKey<T>(classType, foreignObjectAtt.foreignKeyAttribute.parentField.GetValue(classObject), queryExecutor);
|
||||
foreignObject_value = GetByPrimaryKey<T>(foreignObjectAtt.foreignObjectType, foreignObjectAtt.foreignKeyAttribute.parentField.GetValue(classObject), queryExecutor);
|
||||
foreignObjectAtt.parentField.SetValue(classObject, foreignObject_value); // Set the value
|
||||
|
||||
// Now scan the just resolved class to be able to set myself
|
||||
|
Loading…
x
Reference in New Issue
Block a user