ReferencedEntityMap - what should it pick up?

Posts   
 
    
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 13-Jan-2013 10:41:12   

I have an EntityCollection<MoneyTransferEntity>() which has ~1450 items.

I take one of them and attempt to clone it. It is too slow and takes 2.5MB (not using FastSerialization). I assume then it is serializing the whole graph so in the Cloning code, I use a ReferencedEntityMap on the single Entity being serialized and it shows just 4 seen entities - the target itself and 3 child entities (which is actually exactly what I want to clone).

I have an auditor which relies on using ReferenceEntityMap to detect every entity within a graph and attach itself to those entities and set event handlers.

If ReferenceEntityMap is not picking up every entity within a graph then I have a big problem, so my question is what exactly should ReferenceEntityMap be picking up?

Also, I need to be able to 'clone' the 4 entities mentioned above regardless of the fact that they are in a collection. If binary serialization is not an option, what exactly do I need to do to make an exact duplicate of the parent entity and its 3 child entities?

(Latest version of v3.5)

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Jan-2013 05:00:36   
  • How does look your cloning code?
  • Did you see this thread already?
  • If I understand you correctly, you are using ReferenceEntityMap.GetSeenEntities() and it's working, Right?
David Elizondo | LLBLGen Support Team
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 14-Jan-2013 11:23:14   

This is the code...

        public static T CloneEntity<T>(T entity) where T: EntityBase2
        {
            if (entity == null) return null;

ReferencedEntityMap x = new ReferencedEntityMapAce(entity);

            var formatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.Clone));
            var stream = new MemoryStream();

            formatter.Serialize(stream, entity);

            stream.Seek(0, SeekOrigin.Begin);

            return (T) formatter.Deserialize(stream);
        }

x.GetSeenEntities() is returning 4 entities.

I had a look at the thread you mentioned and tried ObjectGraphUtils.ProduceTopologyOrderedList and that too showed 4 entities.

So everything points to that graph having only 4 entities yet the stream.Length is 2.5MB? Was I mistaken in assuming that an entity within a standalone EntityCollection<T> would be 'connected'to it siblings. That would be great if so!

The only other thing is the Auditor I have attached. I had been playing about trying to get it working with FastSerialization, maybe I didn't revert it back correctly. I'll check.

simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 14-Jan-2013 11:36:53   

The auditor was indeed the case. confused

    [NonSerialized]
    object target;

The NonSerialized attribute was not put back correctly so the target must have been serialized again which is surprising since I thought binary serialization took care of references???

When I put the attribute back, the stream length is 15,522 bytes but of course the Auditor is now no longer working since it doesn't have a target disappointed

Switching on FastSerialization leaves the stream as 772 bytes (sunglasses ) but won't serialize the Auditor which is probably better since I can just create a new one for the clone.

It would have been nice to be able to have a choice of whether to use FastSerialization or not though.

Any thoughts?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Jan-2013 01:04:37   

Switching on FastSerialization leaves the stream as 772 bytes (Cool) but won't serialize the Auditor which is probably better since I can just create a new one for the clone.

It would have been nice to be able to have a choice of whether to use FastSerialization or not though.

Not sure I understand the question. You managed to switch on FastSerialization, and yet asking for having this as a choice?!

simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 15-Jan-2013 08:11:11   

Hi Walaa

I've probably talked myself around in circles - sorry about that. What I meant to say is that it would have been nice to be able to have fast serialization on or off and get the same result. That isn't possible because fastserialization on won't serialize the auditor at all and fastserialization off will serialize it but will take 2.5mb (when object target is serializable) or will have no target rendering it useless (when object target is marked NonSerialized).

No matter, I've decided to replace the auditor whichever method I use.

The question I still have outstanding is about whether it is safe to clone an entity that is contained in a standalone EntityCollection. When I say safe, I mean that ReferencedEntityMap will not see the other entities in that same standalone collection.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Jan-2013 17:55:30   

I don't see anything against this being safe. Cloning doesn't and shouldn't probe the siblings.