You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to create an application.
You use Plain Old CLR objects (POCO) to model your entities.
The application communicates with a Windows Communication Foundation (WCF) Data Services service.
You need to ensure that entities can be sent to the service as XML. What should you do?
A.
Apply the virtual keyword to the entity properties.
B.
Apply the [Serializable] attribute to the entities.
C.
Apply the [DataContract(IsReference = true)] attribute to the entities.
D.
Apply the [DataContract(IsReference = false)] attribute to the entities.
Explanation:
DataContractAttribute Specifies that the type defines or implements a data contract and is serializable by a serializer,
such as the DataContractSerializer. To make their type serializable, type authors must define a data contract for their type.
IsReference Gets or sets a value that indicates whether to preserve object reference data.
Even though I realize this is the official answer, it isn’t quite the whole picture. In addition to the [DataContract] attribute, you also need to add [DataMember] attributes to each property to be serialized.
WCF accepts any serializable POCO object. [Serializable] would work in this case, without needing to decorate each member with an attribute, as long as there are no circular references to/from other entities, and as long as all the public/protected fields and properties are of serializable data types.