Patrick\’s Bytes

26, April 2008

Using LINQ to SQL as data contract for WCF/ Web Service

Filed under: .NET Programming,LINQ,Visual Studio 2008 — patrickyong @ 8:27 am

LINQ to SQL greatly enhance our coding productivity but when it comes to serialization of the object (means using LINQ to SQL Object as data contract) for used in WCF as data contracts, its a headache as it does not really support binary or XML serialization out of the box.

The immediate solution is to create your own data contract and copy the data from your LINQ to SQL object to properties in the data contract. This approach is good as a quick fix but it is counter productive of retyping everything. On the mean time I think there us overhead of doing so as well.

So the solution is write a native helper class to take care of the serialization using reflection (I bet you will complain there is overhead using reflection as well!) but it up to you as I found somewhere in Code Project the solution to do this is published.

http://www.codeproject.com/KB/dotnet/linqsqlserialization.aspx

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: