Serialization

Posts   
 
    
Posts: 3
Joined: 23-Jan-2008
# Posted on: 23-Jan-2008 09:18:00   

Hi,

I'm in situation that i need change LLBLGEn default serialization behaivor as when i serializer object, only object id (only object primary key in my context) store and in deserialization i use that id then load entity by Adaptor.

i used fallowing code to serialize id:

public override void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("_identifier", this.Fields.PrimaryKeyFields[0].CurrentValue); }

now i want to deserialization it by loading entity using adaptor and assign loaded entity values to current entity (this keyword refrence). how the best way to achive this goal?

thank in advance.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 23-Jan-2008 10:10:19   

Answered via email simple_smile

(for clarity: Send entity over the wire, deserialize it normally, then use that entity to fetch the one from the db. There's no way to do this during deserialization, as that builds an entity graph, you can't inject fetching there. )

Frans Bouma | Lead developer LLBLGen Pro
Posts: 3
Joined: 23-Jan-2008
# Posted on: 23-Jan-2008 11:01:45   

hi, thank for your quick reply, But the reason that lead me to choice described approach (first thread post) was that my Entity field changes from serialization to deserialization, I mean when i serialize object its version is 1.0 and havn't "cost" (for example) field and have "number" field, but in deserialization my object version is 2.0 and have "cost" field and havn't "number" field.

I used the fetch in deserialization to overcome the versioning probelm.

do you have any idea?

I think (but not confident) that i don't need related object serialization (and so deserialization) entirely, any way if you have a solution for by this simplified condition its thank to read for me, but a solution without this consideration (meen that serialize/deserialize related object) is so better.

thanks.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-Jan-2008 11:21:03   

my Entity field changes from serialization to deserialization, I mean when i serialize object its version is 1.0 and havn't "cost" (for example) field and have "number" field, but in deserialization my object version is 2.0 and have "cost" field and havn't "number" field.

Do you mean the value of these fields change from v.1.0 to v.20 or do you that the entity itself has different schema per version?

IMHO if you are only serializing and deserializing the PK only, then I think you don't need entity serialization/deserialization in the first place. You can manage this outside of the entity boudaries.

Posts: 3
Joined: 23-Jan-2008
# Posted on: 23-Jan-2008 11:32:17   

Hi, Entity schema changed from version1.0 to version2.0. Serialization done by using context (for my example is WWF) and i can't stop it, i mean context serialize and deserialize my LLBLGen geretaed entities and from serialization time to deserializtion time, entity schema change and so fail to deserialize. So i decide to serialize PK and and fetch entity by PK in deserialization to overcome schema inconsistency (versioning) problem.

Thanks for your reply.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 23-Jan-2008 13:33:11   

If schema changed you HAVE To version the service interface as well. What you try to do is work around a schema change which is actually not really a good idea: you should introduce a new version of the interface a client connects to (so a different service).

Frans Bouma | Lead developer LLBLGen Pro