In the question titled

How to use Dataobject.net with WCF

Alexey Kulakov wrote

DataObject.Net has serialization of Entities...

I can find no reference to serialization in the DO documentation. How can an Entity object be serialized?

asked Nov 13 '14 at 13:34

TimB's gravatar image

TimB
7558

edited Nov 13 '14 at 13:35


2 Answers:

I've been experimenting with the "Simple example" code provided by Support, and from what I can tell, it doesn't work at all if the stream is not deserialized within the same process that serialized it to begin with. The stream appears to contain no actual data (perhaps it has a reference to a cached object in memory?). In other words, as far as I can tell, the object has not actually been serialized. Sending the serialized object to another process (sort of the whole point of serialization) won't work this way.

answered Nov 20 '14 at 10:26

TimB's gravatar image

TimB
7558

edited Nov 20 '14 at 10:34

Hi TimB

Simple example for you


// formatter for serialization
BinaryFormatter formatter = new BinaryFormatter();
.....
//serialization
using (var session = Domain.OpenSession()) {
  using (var transactionScope = session.OpenTransaction()) {
    Company company = new Company {Name = companyName};
    //This is DO serialization context
    using (new SerializationContext(entity => SerializationKind.ByReference).Activate()) {
      // serialization to stream
      formatter.Serialize(stream, company);
    }
    transactionScope.Complete();
  }

//deserialization
using (var session = Domain.OpenSession()) {
  using (var transactionScope = session.OpenTransaction()) {
    stream.Position = 0;
    Company deserializedCompany = (Company) formatter.Deserialize(stream);
  }
}

answered Nov 14 '14 at 04:29

Alexey%20Kulakov's gravatar image

Alexey Kulakov
70215

Alexey, does the deserialization need to be into the same database? Or will any database with a compatible table work?

(Nov 19 '14 at 15:46) TimB TimB's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA