In the question titled "Serializing a persistent object", I asked how to serialize an object. The sample code provided doesn't seem to work, in the sense that it doesn't actually serialize the object into a form that can be communicated to another process (which of course is the whole point of serialization). The resulting stream contains no data; I speculate that it contains a reference to a cached in-memory object. In any case, as far as I can tell, the data in the stream is unusable outside the context of the process that created it.
|
Hi TimB This explanation is more useful. First of all, in example in "Serializing a persistent object" question I used SerializationKind.ByReference. When SerializationKind.ByReference used then DO try to check that all references. So DO make a query to database on deserialization. I think it's my bad. Did you try to use SerializationKind.ByValue? About XML serialization. I know that XmlSertializer requires constructor without parameters for type. Entity contains constructor without parameters but this constructor initializes entity with new key. And you can't change it after initialization. Build-in deserialization uses special constructor of Entity. Also, want to say: 1) You said that some Entities may do not use in some layers. So why do you want to create useless tables. Even if your model would be different in different layers, you must keep in synchronized state. I mean that DO have type identifier for each type and it can be different in different domains. Current type identifier defined by sequence of values and already defined type identifiers (takes form stored metadata). You can define identifier manually, but then you must take care about it. 2) POS layer don't need DO at all. I think, building of domain on POSs just for deserialize Entity is bad idea. 3) DO can lazily resolve all the references, when serializer will traverse the graph and in some cases you'll see the whole graph serialized. So I think that using of DTO is good for you. |
Hi TimB.
Once again. You have two sides - server application (or service), which has access to database (Server database) and uses DO; client application (WPF, WinForms,Windows service, Asp.net application, whatever) which has no access to server database. Does client application have it's own database? Do they use one DO types model? Or maybe client application just deserialize XML to some object with same structure as Entity on server side and do not need DataObjects at all?
The clients in my case are POS devices that have limited capabilities. They might have SQLite for certain functions, but the databases that contain the information needed for processing transactions reside on store and corporate servers. My goal is to have a single unified object model across all layers, even though some layers will not use certain parts of the model. Using DO, we can build the domain for Oracle on the corporate servers, and MySQL on the store servers. In theory, we could even build it for SQLite on the POS systems, but the data would generally not be available (continued)
at this level. There is a message queue system that supports communication across servers. Here's an example. A customer wishes to return an item to store A which was purchased at store B earlier in the day. The transaction might not have reached the corporate server yet. Store servers have no knowledge of each other, but they do know about message queue channels. Store A requests the complete transaction record using a message, and store B responds. It is the content of that response message that is the key to my problem. Store B has retrieved a class Transaction : Entity (continued)
record from its database (with aggregated details such as item records and tender records). That record needs to be communicated to the store A server, and from there to the POS system where the transaction is being processed. What I would like to do is (XML) serialize the record at store B, then place it in the message for ultimate delivery to the POS system, where it would be deserialized into either a Transaction : Entity object (that would be most convenient), or an object of a non-Entity class generated automatically from the same source code. The schema is fairly complex. (continued)
What I'm trying to avoid is having to maintain parallel Entity and DTO classes. If that's not possible using DO, perhaps it is at least possible to generate the DTO classes from the same codebase (I think I know how to do this). I could even maintain the DO model on the POS systems in SQLite if that would facilitate object transfer. But so far, I've been unable to successfully serialize the Entity objects on the server as a first step. Do you see a way to make this work?