Serialization of custom entity properties within Collection or UnitOfWork

Posts   
 
    
rbrown
User
Posts: 36
Joined: 11-Jun-2008
# Posted on: 12-Apr-2012 16:11:22   

What is the proper way to ensure a custom property gets serialized?

We have added a custom property to enable/disable some custom pre-save logic during the save of the entity on the server (using .NET Remoting between client/server).

[Browsable(false)]
[DefaultValue(false)]
pubilc bool DisableCustomSaveLogic {get; set;}

(this allows us to bypass some extensive custom business logic when doing imports from external systems)

It seems that when we pass a single entity across the remoting wire, the property is correctly serialized/deserialized. However, when passing it as part of a EntityCollection<T> or UnitOfWork the property always has the default value when it is deserialized. In other words, it is not be serialized/deserialized in this case.

We are using SerializationOptimization.Fast

I've tried various approaches using the OnGetObjectData/OnDeserialized. Also I have tried using CustomXmlSerializationAttribute and overriding PerformCustomXmlDeserialization/PerformCustomXmlSerialization, with no success so far... although I couldn't find a good example of this, so perhaps I didn't do it correctly.

Can you tell me the proper way to make sure this property gets serialized correctly in both scenarios (simply passing the entity across, as well as part of a collection/uow)?

LLBLGen 2.6, Adapter (with manager templates), .NET 4.0, SQL Server 2005+

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 12-Apr-2012 20:59:02   

It's in the docs. You need to use Des/SerializeOwnedData.

If you still experience problems please post more info (http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7722).

David Elizondo | LLBLGen Support Team
rbrown
User
Posts: 36
Joined: 11-Jun-2008
# Posted on: 12-Apr-2012 23:19:05   

Ah yes! Sorry I guess I missed it in the docs originally. This works:

        protected override void SerializeOwnedData(SerializationWriter writer, object context)
        {
            base.SerializeOwnedData(writer, context);
            writer.Write(DisableCustomSaveLogic );
        }

        protected override void DeserializeOwnedData(SerializationReader reader, object context)
        {
            base.DeserializeOwnedData(reader, context);
            DisableCustomSaveLogic  = reader.ReadBoolean();
        }

Follow up question for version tolerance:

Is there an easy way to check for existence there before attempting to read from the SerializationReader? My app is a distributed client/server app, so there is inevitably going to be a period of time where the client(s) and server are not running the same version of my code. Do you have any suggestions for how to handle this gracefully? (e.g. new server expects custom property, but old client did not send it)

Something like this pseudocode:

        if( reader CONTAINS DisableCustomSaveLogic )
                DisableCustomSaveLogic = reader.ReadBoolean();

Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Apr-2012 10:03:10   

This is a Design question, and personaly I recommend the approach mentioned here: http://stackoverflow.com/questions/10011690/client-compatibility-check-management

It's up to you whether the client passes its version info to the server on the start of a session, or with every call (not recommended). Or the server can ask for the client's version when needed.

Another approach, is for the client to check for the server version before calling specific methods.