We have seen many articles and blogs talking about using WCF Data Service with ADO.Net Entity model generated class as model. In this article we are going to see, how to use WCF Data Service with LINQ to SQL Class.
There are three conditions while using LINQ to SQL class with WCF Data Service. One of below condition must be true
1. The Primary Key column of the table must have name ID.
2. Primary key column of the table must have ID appended to that. For example name of the column should be in the format EmpID, ProductID , RollNoID etc.
3. Third is, let us say you have to expose CRUD operation on your existing data base where you cannot change the existing columns. In that case follow the below steps
Step1
Launch visual studio and create a web application
Step2
a. Right click on the web application project and add data model using LINQ to SQL class.
b. Click on .cs file
c. Add the namespace System.Data.Services.Common on the class DataClasses1.designer.cs
d. Locate the entity class and put the DataServiceKey attribute
Above SpeakerId is name of the primary key column in the table Blogger.
Step 3
a. Right click on the Web Application project and add a new item by selecting WCF Data Service from Web Tab
b. Now provide the data class context name as the model.
Now we are done and we can run the WCF Data Service .
Leave a Reply