Tuesday, January 06, 2009

WCF and Linq to SQL

Since Linq to SQL creates a nice data model, there is no point in re-creating the entities again as DataContract objects that can be serialized and sent to clients. Linq entities can be used directly, saving you some time. But, this is not the default behavior.
To enable this behavior open the data model (dbml) in designer and then go to Properties. Adjust Serialization Mode to Unidirectional as in the image below

That is all. The entity objects are now serialized and can be returned directly from a web service call. They can be sent either individually or as a part of a collection/list. Wonderful.

No comments: