Using Linq with WCF

I am looking for examples or guidelines for using Linq over WCF (n-tier application). Indicate if you are showing something for Linq-to-SQL or Linq-to-entity. I would like to see usage examples for both.

I am wondering how things like deffered execution work on WCF (if it works at all)? Support for circular references, etc.

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

+5
source share
3 answers

There is no LINQ provider that I know of for general WCF-based queries. LINQ to ADO.NET Data Services , however, allows you to query the Entity model by 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);
      }
   } 
+7
source

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

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

+2
source

ADO.NET Data Service is probably the best. The codeplex interlinq project was implemented to be able to use arbitrary LINQ expressions with WCF, which can then be processed by another LINQ provider, such as LINQ to NHibernate or LINQ to SQL. Unfortunately, this project is not very active.

Good luck.

+1
source

All Articles