Serializing Objects (Entity Framework)
Entity types generated by the Entity Data Model generator tool (EdmGen.exe) and the Entity Data Model Wizard have SerializableAttribute and DataContractAttribute applied. This enables objects to be serialized by using binary serialization, XML serialization, and Windows Communication Foundation (WCF) data contract serialization. For more information, see Web Services and the Entity Data Model (Application Scenarios).
The following considerations apply when serializing and deserializing entities:
When you serialize an object, the EntityKey object is also serialized.
When you use binary serialization and WCF data contract serialization, if the object being serialized has related objects in the object graph, those objects are also serialized. XML serialization does not serialize related objects.
Only object properties and relationship information are serialized. Object state information maintained in the object context is not serialized.
After an object is deserialized, it is in the Detached state. For more information, see Attaching Objects (Entity Framework).
Because entity types support binary serialization, objects can be saved in the view state of an ASP.NET application during a postback operation. When required, the object and its related objects are retrieved from the view state and attached to an existing object context. For more information, see How to: Serialize and Deserialize Objects (Entity Framework).
See Also
Other Resources
Managing the Object Context (Entity Framework)
Working with Objects (Entity Framework)