Sql – How to move from LINQ to SQL to “LINQ to WCF”


I'm putting together a WPF application which will eventually use WCF web services as its data source.

During the prototyping phase, I'm using LINQ to SQL on an SQL 2008 database and have come to appreciate the ease with which I can do "Add New Item | LINQ to SQL Classes" and generate a model class for a table, then speak to it with LINQ and pass this to my XAML UI, very nice.

But what happens when we switch the datasource from SQL Server to WCF web services? In order to continue using LINQ, am I going to have to:

  • write my own LINQ-to-web-service classes manually (using IQueryable etc.?)
  • is there a code generation tool that does this, something like "LINQ-to-WCF" (strange that this term doesn't even come up in Google)
  • or will I have to inefficiently get large amounts of records from my web service, create objects out of them, and then to LINQ-to-objects to query them?

Thanks for any direction you can give here.

ADDED: thanks for the answers, very helpful, but led to some confusion:

  • this MSDN tutorial says to "Add New Item | ADO.NET Entity Data Service"
  • I have VS2008 and can just do "Add New Item | ADO.NET Entity Data Model"
  • this MSDN video says to create a new project with the ADO.NET Data Service template which I don't have in VS2008
  • what are the differences between all of these, which are used most commonly?
  • and from what I have read so far anything that has to do with "LINQ to Entities" entail costs whereas "LINQ to SQL" is free, so do the "Entity Data Service/Model" options above have to do with LINQ to Entities?

Best Solution

You'll probably want ADO.NET Data Services. You'll have to add an IUpdatable interface implementation to your entities, and you can use LINQ to SQL, Entity Framework, SubSonic, or a number of others. We're using the CodeSmith PLINQO templates, which allow you to add this functionality to LINQ to SQL.