internal void SetRefFieldValue(int tableNumber, string fieldName, int fieldOrdinal, SoodaObject newValue, SoodaObject[] refcache, int refCacheOrdinal, ISoodaObjectFactory factory) { if (newValue != null) { // transaction check if (newValue.GetTransaction() != this.GetTransaction()) throw new SoodaException("Attempted to assign object " + newValue.GetObjectKeyString() + " from another transaction to " + this.GetObjectKeyString() + "." + fieldName); } EnsureFieldsInited(); EnsureDataLoaded(tableNumber); SoodaObject oldValue = null; SoodaObjectImpl.GetRefFieldValue(ref oldValue, this, tableNumber, fieldOrdinal, GetTransaction(), factory); if (Object.Equals(oldValue, newValue)) return; object[] triggerArgs = new object[] { oldValue, newValue }; if (AreFieldUpdateTriggersEnabled()) { MethodInfo mi = this.GetType().GetMethod("BeforeFieldUpdate_" + fieldName, BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public); if (mi != null) mi.Invoke(this, triggerArgs); } Sooda.Schema.FieldInfo fieldInfo = GetClassInfo().UnifiedFields[fieldOrdinal]; StringCollection backRefCollections = GetTransaction().Schema.GetBackRefCollections(fieldInfo); if (oldValue != null && backRefCollections != null) { foreach (string collectionName in backRefCollections) { PropertyInfo coll = oldValue.GetType().GetProperty(collectionName, BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Public); if (coll == null) throw new Exception(collectionName + " not found in " + oldValue.GetType().Name + " while setting " + this.GetType().Name + "." + fieldName); ISoodaObjectListInternal listInternal = (ISoodaObjectListInternal)coll.GetValue(oldValue, null); listInternal.InternalRemove(this); } } SetFieldValue(fieldOrdinal, newValue != null ? newValue.GetPrimaryKeyValue() : null); refcache[refCacheOrdinal] = null; if (newValue != null && backRefCollections != null) { foreach (string collectionName in backRefCollections) { PropertyInfo coll = newValue.GetType().GetProperty(collectionName, BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Public); if (coll == null) throw new Exception(collectionName + " not found in " + newValue.GetType().Name + " while setting " + this.GetType().Name + "." + fieldName); ISoodaObjectListInternal listInternal = (ISoodaObjectListInternal)coll.GetValue(newValue, null); listInternal.InternalAdd(this); } } if (AreFieldUpdateTriggersEnabled()) { MethodInfo mi = this.GetType().GetMethod("AfterFieldUpdate_" + fieldName, BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public); if (mi != null) mi.Invoke(this, triggerArgs); } }