Sunday, March 28, 2010

Enabling Serialization for DBML files

By default WCF uses Data Contract Serialization which is a slightly more verbose form of XML serialization. And the method to serialize objects using Data Contract serialization is much the same as normal XML serialization. It is just a matter of appending attributes at the beginning of your class and member definitions.

[DataContract()]
[DataMember(Order=n)]

Wherever required. *n indicates the sequence.

So we can go into each dbml file and add these attrubutes and Data Contract Serialization is ready to go.

However... there is a much easier way to do this.

Simply open the properties of the dbml file (from the context menu or the designer or the view menu) and change the Serialization Mode property from 'None' to 'Unidirectional'.


1 comment:

  1. Oh yeah, here is the original post I got this info from...http://blogs.msdn.com/wriju/archive/2007/11/27/linq-to-sql-enabling-dbml-file-for-wcf.aspx

    ReplyDelete