views:

1560

answers:

4

I am looking for any examples or guides to using Linq over WCF (n-tier application). Please specify if you are showing something for Linq-to-SQL or Linq-to-entities. I would like to see usage examples for both.

I am wondering how things like deffered execution works over WCF (if it works at all)? Cyclic references support and so on...

Any information to make this a quick start guide to using Linq with WCF is helpful.

+6  A: 

There isn't any LINQ provider that I'm aware of for generic WCF-based queries. LINQ to ADO.NET Data Services, however, lets you query an Entity model over WCF/REST.

From Andy Conrad's blog:

    static void Main(string[] args)
    {
      var context=new WebDataContext("http://localhost:18752/Northwind.svc");

      var query = from p in context.CreateQuery<Product>("Products")
                  where p.UnitsInStock > 100
                  select p;

      foreach (Product p in query)
      {
        Console.WriteLine(p.ProductName+", UnitsInStock="+p.UnitsInStock);
      }
   }
Mark Cidade
Does this mean that Linq-to-ADO.NET deffered loading works over WCF?!
Phobis
+1  A: 

ADO.NET Data services is probably your best bet. There was a codeplex project interlinq to be able to use arbitrary LINQ expressions with WCF which could then be processed by another LINQ provider, like LINQ to NHibernate or LINQ to SQL. Sadly this project does not appear to be very active.

Good luck.

smaclell
+2  A: 

You can add a Linq to SQL class to a WCF service. Then go to your datacontext in the Linq to SQL class and in the properties set Serialization Mode to Unidirectional.

The entities in your Linq to SQL class will now be available through the WCF service :)

Eric
+1  A: 

Packt Publishing has recently released a book titled WCF 4.0 Multi-tier Services Development with LINQ to Entities. You can read about it here: https://www.packtpub.com/wcf-4-0-multi-tier-services-development-with-linq-to-entities/book