Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Serialize a custom property that is an entity
 

Pages: 1
LLBLGen Pro Runtime Framework
Serialize a custom property that is an entity
Page:1/1 

  Print all messages in this thread  
Poster Message
ww
User



Location:

Joined on:
01-Oct-2004 22:58:25
Posted:
65 posts
# Posted on: 19-Apr-2012 19:33:17.  
Using version 3.5, adapter.

Some of my entities need to hold an instance of another entity, but this relationship is not reflected in the database model since it's a class-level dependency rather than an instance-level dependency.

For example, all instances of EntityA will be holding a reference to an instance of EntityX. All instances of EntityB will be holding a reference to a different instance of EntityX.

EntityX itself has relations to other entities, including possibly other EntityAs and EntityBs.

The EntityAs, EntityBs, etc. get serialized for WCF. On the client side, the client will sometimes need the EntityX that is associated with a particular entity, so I'd like to serialize it along with the EntityA to avoid making a second server call to fetch it later.

I can't, as far as I've been able to figure out, use PerformCustomXmlSerialization, because of infinite recursion problems--working from within PerformCustomXmlSerialization there's no way to track which entities have already been serialized.

I thought about using a model-only relationship so the llblgen framework can handle the serialization fully, but that would require a model-only foreign key field, which isn't supported.

Can anyone think of a way to do this? Or should I just give up make a second server call when I need the EntityX?

  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8065 posts
# Posted on: 19-Apr-2012 23:03:29.  
ww wrote:
I can't, as far as I've been able to figure out, use PerformCustomXmlSerialization, because of infinite recursion problems--working from within PerformCustomXmlSerialization there's no way to track which entities have already been serialized.

PerformCustomXmlSerialization is the way to go. What are the problems you are having there? You can serialize the full graph recursively using a binaryFormatter. For instance:
Code:
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.Clone));
bf.Serialize(ms, o);
ms.Seek(0, SeekOrigin.Begin);
            
var toSerialize = ms.ToString();



David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
ww
User



Location:

Joined on:
01-Oct-2004 22:58:25
Posted:
65 posts
# Posted on: 20-Apr-2012 15:46:59.  
My problem is that the graph of the EntityX being serialized may contain the EntityA that is doing the serializing. I got a stack overflow because of recursion on this. I didn't try the binary formatter, though. I'll take another look.
  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.