LINQ to SQL : Enabling .dbml file for WCF
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.
Now your DataContext and Properties will have the following attributes,
[DataContract()]
[DataMember(Order=n)]
Wherever required. *n indicates the sequence.
Namoskar!!!
Comments
Anonymous
November 26, 2007
LINQ to SQL is object relational model and .dbml file generates the class file for all kind of CreateAnonymous
December 20, 2007
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? ThanksAnonymous
January 30, 2008
CBM - you would manually edit the generated dbml.designer.cs and remove the DataMember attribute of the fields that you don't want serialized.Anonymous
April 18, 2008
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 millionAnonymous
September 06, 2008
Hi New to Linq and was wondering is it possible to convert dbml to sql. I have a project but don't have the database I don't want to manually create the tables if i dont need to.Anonymous
November 24, 2008
The comment has been removedAnonymous
June 21, 2009
Nice and direct approach post.Anonymous
April 10, 2011
This was very helpful for my little project :-) Thanks alot!