LINQ to SQL : Enabling .dbml file for WCF

LINQ to SQL : Enabling .dbml file for WCF

  • Comments 7

LINQ to SQL is object relational model and .dbml file generates the class file for all kind of Create, read, update and delete (CRUD) through the mapping mechanism. Ideally this should allow us to enable it for WCF Service. But for that we have to manually add DataContract and DataMember attributes. We can use .dbml’s designer feature to add those to our code.

 

Simply right click on the dbml designer and press F4 to get the property window, you will get a property “Serialization Mode”. Set it to “Unidirectional”. That’s all. This is simple but very helpful.

 

DBMLWCF

 

Now your DataContext and Properties will have the following attributes,

[DataContract()]

[DataMember(Order=n)]

Wherever required. *n indicates the sequence.

 

Namoskar!!!

Leave a Comment
  • Please add 6 and 5 and type the answer here:
  • Post
  • LINQ to SQL is object relational model and .dbml file generates the class file for all kind of Create

  • but how do i decorate a certain field as [Nonserialized].  I don't want to be sending my object's/record's ID out to the client.  how do i indicate that a field should not be serialized?

    Thanks

  • CBM - you would manually edit the generated dbml.designer.cs and remove the DataMember attribute of the fields that you don't want serialized.

  • I was really getting so confused when I saw dbml generating classes that looked better than the ones generated using xsd.exe. Also this little post just made it clear how to make N-Layer apps using linq...Thanks a million

  • CBM (and anyone else in our situation) - just to clarify, it seems as though the most resilient way of making sure that some properties are non-serialisable is to make them non-public in the DBML GUI designer.

    This will automatically strip off any DataMember attribute from that property when you save the file.

    Much appreciated Wriju!

  • Nice and direct approach post.

  • This was very helpful for my little project :-) Thanks alot!

Page 1 of 1 (7 items)