How to: Serialize and Deserialize Objects To and From Binary Stream

[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 (EDM) generator tool (EdmGen.exe) and the Entity Data Model Wizard support binary serialization. When you serialize an object to a binary stream, all related objects currently loaded into the object context will also be serialized. For more information, see Serializing Objects.

The example in this topic is based on the Adventure Works Sales Model. To run the code in this example, you must have already added the AdventureWorks Sales Model to your project and configured your project to use the Entity Framework. To do this, complete the procedures in How to: Manually Configure an Entity Framework Project and How to: Manually Define the Model and Mapping Files. You must also add using statements (Imports in Visual Basic) for the following namespaces:

Example

In this example, a SerializeToBinaryStream method queries for the Contact object for the specified last name value, and returns a binary MemoryStream. The MemoryStream contains an object graph of the Contact object and its related SalesOrderHeader and SalesOrderDetail objects.

See Also

Show: