Serializing and deserializing entity instances
Serialization
is defined as the process of converting an object into a stream of bytes (as a memory stream) so that it can be persisted in the memory or to a permanent storage device such as a database or a file. You can serialize or deserialize an entity instance using ObjectContext
. To do this, you need to call the Serialize
or the Deserialize
method of the BinaryFormatter
class as shown in the following code snippets:
public static void Serialize(sString fileName, oObject obj) { BinaryFormatter var binaryFormatter = new BinaryFormatter(); FileStreamvar fileStream = new FileStream(fileName,FileMode.Create); try { binaryFormatter.Serialize(fileStream, obj); } catch (SerializationException ex) { throw new ApplicationException("The object graph could not be serialized", ex); } ...