Freigeben über


Exposing LINQ Generated Classes through WCF

The lure of using LINQ to generate classes and expose them as data contracts through WCF is extremely attractive.  The designer-driven LINQ to SQL interface allows for generation of LINQ classes based on database objects (i.e., tables and stored procedures).  The power here is that if any of those elements change, generation of the classes to accommodate those changes are easy and maintainable. 

However, combining LINQ and WCF before Orcas was daunting because the LINQ classes were generated code.  Any decoration of the methods there (required by WCF in order to make the LINQ classes data contracts) would easily be overwritten because the dbml designer would overwrite the accompanying .cs file which contained the definition of the LINQ classes.  With Orcas Beta 2 there is a Serialize Mode property on the dbml design space that allows for the automatic decoration of the LINQ classes for WCF exposure.

Now you can automatically decorate your LINQ classes for WCF and specify namespaces for them without writing code and all through the LINQ to SQL designer.  Simply focus the designer (don't select any classes) and examine its property sheet as below.  Serialization Mode is normally not set.  By specifying a serialization mode, all of the code receives the corresponding DataContract and DataMember attributes.

 

image

Comments