LINQ to SQL Class in ADO.NET Data Service

I have had very tough time in finding out how to use LINQ to SQL class as data model for ADO.NET Data Service.  I did many of  sample on ADO.NET Data Service using Entity Data Model. I have posted many article on that too on  our site , but I had no idea that using LINQ to SQL class is bit more differnet.  never  late , I am going to point out , how to use LINQ to SQL class in ADO.NET Data Service.

Refrernce Key in table must satisfy one of these three criteria

1.  be named ID
2.  be named [entityname]ID
3.  put [DataService(" ")] attribute on the type and specify the key property name.

Explanation

1. There must be one column named ID exist in the table. OR
 
2.  There must be one column named [entityname]ID  exist in the table.
For Example , if table name is Product then there must be one column called ProductID exist.  OR

3.  If you don't want to modify existing databse and still want to use with ADO.NET  Data Service, put

[DataServiceKey(" ")] attribute on the type and put key name inside the double quotes.

What , I mean to say here is that

a.  Include namepsace System.Data.Services.Common  in the class generated by LINQ     to   SQL

b.  put attribute [DataServiceKey(" ")] above the class
.
c.  put name of the key in the quotes , if key is empid  atrribute would be
    [DataServiceKey("empid ")]

Do one of three and you are done to use LINQ to SQL Class with ADO.NET DATA service.

For details on ADO.NET Data Service , read my other articles on this site

happy Coding.



Ebook Download
View all
Learn
View all