Did you find a bug in Opf3? Can you reproduce it? Let us know, we'll try to fix it as soon as possible!
 | |
| | I have a master object that has a collection of sub object
[Relation("Id = ObjectId")] private ObjectSetHolder<SubObject> _subObjects = new ObjectSetHolder<SubObject>();
the subobject has a reference to the main object
[Relation("ObjectId = Id", PersistRelationship = PersistRelationships.ChildFirst)] private ObjectHolder<MainObject> _mainObject = new ObjectHolder<MainObject>();
the main object looks to delete the sub objects on delete
public override void OnBeforeRelationsPersist(RelationsNotificationEventArgs e) { if (e.PersistentOperation == PersistentOperations.Delete) { _subObjects.InnerObject.RemoveAll(); e.Context.PersistChanges(_subObjects.InnerObject); } }
what seems to be happening is in the PersitChanges in OnBeforeRelationsPersist when the subObject is being deleted it is also trying to delete the main object as well becuase it references it...... if i remove the objectHolder for the mainobject from the subobject then everything works ok.
Am I doing something wrong or is this a problem.
Regards.
|
 | |
| | Aren't you deleting also the main object? I mean the PersistOperations is only on Delete if the main object is deleted too...
Regards, Christian
|
 | |
| | Yes I am trying to delete the main object but the sub object seems to also try to delete the main object , which hen tries to delete its subobjects until a stack overflow is reached.
|
 | |
| | Stephen Scott wrote: Yes I am trying to delete the main object but the sub object seems to also try to delete the main object , which hen tries to delete its subobjects until a stack overflow is reached.
Hi Scott, you should try to specify the PersistDepths when deleting the related objects.
e.Context.PersistChanges(objects, PersistDepths.Flat);
This just deletes the objects and does not walk the graph.
Regards, Christian
|
 | |
| | But the subobject do contain other sub objects that do need to be deleted. The proplem is becuase the subObjects reference to the main object is not going to be the same physical object it doesnt recognise it as already being processed.
I am just going to have to remove parent objects from subobjects and count it as a limitation of opf.
|
 | |
| | Hi,
there is another way. Do you have the latest version. We have implemented a little cache manager there. You could set the SimpleCacheManager when creating the ObjectContext. That one just returns you the same object instance if you do the following.
Parent -> Children -> Parent
Parent is in both cases the same instance.
context.CacheManager = new SimpleCacheManager();
You can also share the simple cache manager with different ObjectContext instances. It is threadsafe.
Regards, Christian
|
 | |
| | I'm guessing this is no good to me as I am using ISelfContainingObject and objects are being loaded and saved in a stateless server object.
|
 | |
| | Hi,
you could consider another option and that is enable cascade deletes in the database. I don't know which DB you are using, but for most databases (such as SQL Server, Access, Oracle, ...) you can specify "cascade delete" when creating a relation in the database. That would then delete all entries that hold a foreign key to the object that you delete.
That would work for your problem.
Regards, Christian
|
 | |
| | I cant use database cascade deletes as SQL Server 2005 wont accept them as there is potential for recursive loops becuase of some of the relationships
|
 | |
| | Stephen Scott wrote: I cant use database cascade deletes as SQL Server 2005 wont accept them as there is potential for recursive loops becuase of some of the relationships Ah! Ok. Well that makes it harder then. I guess this is a combination of two things: recursive loops (= no cascade delete) and stateless (= no caching) - I guess webservices - which make it difficult to work here...
Christian
|