This article will show you how to generate serializable entities by implementing the ISerializable interface

You can enable Serialization for your persistent classes when you are creating your model via the New Domain Model or New Fluent Model wizards. Alternatively, using the Model Settings dialog, you can enable serialization for an already createdDomain Model. Here is the process you would need to go through in order to make your entities serializable:

Navigate to the Code Generation Settings screen of the New Domain Model or New Fluent Model wizard. If you are working with an already created model, open the Model Settings dialog and navigate to the Code Generation tab.

Check the Implement ISerializable checkbox.

You can specify whether to serialize Reference and CollectionNavigation Properties using the Ignore Reference Associations and Ignore Collection Associations checkboxes respectively. By default those checkboxes are checked meaning that Reference and Collection navigation properties willnot be serialized.

Click Finish to complete the wizard or OK if you are using the Model Settings dialog.

If you are using the Model Settings dialog save the model in order to regenerate it according to the updated code generation settings.

The persistent classes will be generated implementing the ISerializable interface and will be decorated with the Serializable attribute. Additionally you can customize the serialization and deserialization behavior for your entities by implementing the CustomizeSerializationProcess and CustomizeDeserializationProcess partial methods. The following is an example of a serializable entity: