Export (0) Print
Expand All

Serializing Objects

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

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 Building N-Tier Applications.

The following considerations apply when serializing and deserializing entities:

  • When serializing entities, the user should consider disabling lazy loading. Otherwise, lazy loading will be triggered and the object graph that is serialized might include more data than expected. For more information about lazy loading, see Loading Related Objects.

  • 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. Starting with .NET Framework version 4, self-tracking entities can contain their own change-tracking logic. For more information, see Working with Self-Tracking Entities..

  • After an object is deserialized, it is in the Detached state. For more information, see Attaching and Detaching Objects.

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 To and From Binary Stream.

In This Section

See Also

Show:
© 2014 Microsoft