This question is locked. New answers and comments are not allowed.
Hi
The way OpenAccess manages collections is causing me some difficulty when I delete an object that's part of a collection using ObjectScope.Remove - the deleted instance is not removed from any tracked collection that's already been loaded so subsequent accesses of that collection lead to exceptions.
Here's a simple example. I have two classes, A and B with a one-to-many relationship, ie A has a field: IList<B> RelatedBs and B has a field A RelatedA. If I have instances a1 and b1, b2 and b3 such that a1.RelatedBs yields [b1, b2, b3] and execute the code roughly:
for each (var b in a1.RelatedBs) Trace.WriteLine(b.ToString());
scope.Remove(b1);
for each (var b in a1.RelatedBs) Trace.WriteLine(b.ToString());
then the 2nd pass through the collection fails because it tries to use a deleted object, throwing:
Telerik.OpenAccess.Exceptions.InvalidOperationException : It is not allowed to read or to write an instance marked for deletion.
I can make this work by setting the reference field on the B to be null, but that feels clumsy. Does anyone know a way to get OpenAccess to do this automatically?
[I can also make it work by removing the instance from the collection, but that's not viable in my real world scenarios - it could cause large collections to be fetched when they were not needed.]
Best regards, Peter
The way OpenAccess manages collections is causing me some difficulty when I delete an object that's part of a collection using ObjectScope.Remove - the deleted instance is not removed from any tracked collection that's already been loaded so subsequent accesses of that collection lead to exceptions.
Here's a simple example. I have two classes, A and B with a one-to-many relationship, ie A has a field: IList<B> RelatedBs and B has a field A RelatedA. If I have instances a1 and b1, b2 and b3 such that a1.RelatedBs yields [b1, b2, b3] and execute the code roughly:
for each (var b in a1.RelatedBs) Trace.WriteLine(b.ToString());
scope.Remove(b1);
for each (var b in a1.RelatedBs) Trace.WriteLine(b.ToString());
then the 2nd pass through the collection fails because it tries to use a deleted object, throwing:
Telerik.OpenAccess.Exceptions.InvalidOperationException : It is not allowed to read or to write an instance marked for deletion.
I can make this work by setting the reference field on the B to be null, but that feels clumsy. Does anyone know a way to get OpenAccess to do this automatically?
[I can also make it work by removing the instance from the collection, but that's not viable in my real world scenarios - it could cause large collections to be fetched when they were not needed.]
Best regards, Peter