How big are serialized entity instances?

Posts   
 
    
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 01-Apr-2009 16:20:14   

Hi there,

I'm keen to use SQL Server session state so that users don't lose their state (shopping cart info) upon an application restart. I'm just interested to know how much space serialized entities take up compared to a stripped down custom entity which I can copy over to a LLBLGen entity when I ultimately want to persist changes to the db.

Also, if I have two entity instances both referencing a different third instance, when the first two instances are serialized, will there be two copies of the third instance or will there just be one?

Cheers, Ian.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 01-Apr-2009 16:27:39   

It depends on how big your entity is. But as a general rule you should avoid storing complex objects in the session.

Please check thie relevant thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12514

Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 01-Apr-2009 16:36:40   

OK, so I should create light weight objects to store data in session or just put the primitive values directly in the session dictionary.

But where do I hook into ASP.net to do this?

It seems that if I do this then all I'm really doing is providing a different type of serialization. Couldn't LLBLGen do this automatically?

Also, won't I lose all the persistance state informtation thats stored in the entity instances?

Another question, what is the definition of a 'complex type'? Does it mean any struct or class?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 01-Apr-2009 17:34:44   

But where do I hook into ASP.net to do this?

This depends on your business, you store things in the session whenever there is a need to.

It seems that if I do this then all I'm really doing is providing a different type of serialization. Couldn't LLBLGen do this automatically?

I think not, again this is a purly business related issue. What to store/cache in the session and when varies from an application to another.

Also, won't I lose all the persistance state informtation thats stored in the entity instances?

Web applications are stateless by nature. A state of an object should be lost after a postback, only data can e maintained across postbacks or during the lifetime of the session/application.

Another question, what is the definition of a 'complex type'? Does it mean any struct or class?

Yes.

Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 01-Apr-2009 17:49:52   

Hi Walaa,

I think not, again this is a purly business related issue. What to store/cache in the session and when varies from an application to another.

What I mean is that I put an LLBLGen entity instance into session and LLBLGen provides a custom serialization mechanism that automatically stores _only _the values of the instance's primitives. So all persistance state, references to other objects etc. would be stripped out or at least transformed into a very basic form.

This would save me from having to create lightweight data classes and worry about transforming them into LLBLGen obejcts. (Err... maybe I'm talking about something like the memento pattern. wink )

Having said all this, it might be easier to just stick the business object back in the database instead of putting it in session! Would be the same effect.

Ian.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 02-Apr-2009 11:19:04   

For lightWeight classes, please search the forum for DTO, you will find some threads with templates attached to generate DTO classes for you.