5

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.

3 Answers 3

7

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);
      }
   } 
Sign up to request clarification or add additional context in comments.

1 Comment

Does this mean that Linq-to-ADO.NET deffered loading works over WCF?!
2

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 :)

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.