Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expose IQueryable Over WCF Service

I've been learning about IQueryable and lazy loading/deferred execution of queries.

Is it possible to expose this functionality over WCF? I'd like to expose a LINQ-to-SQL service that returns an IQueryable which I can then perform additional queries on at the client, and finally execute using a .ToList(). Is OData format applicable at all in this context?

If possible, what is the term for this technique and what are some good tutorials I can follow? Thank you.

like image 957
Trust Avatar asked Nov 27 '10 11:11

Trust


3 Answers

You should check WCF Data Services which will allow you to define Linq query on the client. WCF Data Services are probably the only solution for your requirement.

IQueryable is still only interface and the functionality depends on the type implementing the interface. You can't directly expose Linq-To-Sql or Linq-To-Entities queries. There are multiple reasons like short living contexts or serialization which will execute the query so the client will get list of all objects instead of the query.

like image 130
Ladislav Mrnka Avatar answered Oct 07 '22 02:10

Ladislav Mrnka


as far as i know, the datacontext is not serializable meaning that you cannot pass it around with WCF

like image 30
Ali Tarhini Avatar answered Oct 07 '22 01:10

Ali Tarhini


You can use http://interlinq.codeplex.com/ which allows you to send Linq query over WCF.

WCF Data Services only can be using with webHttpBinding and not all Linq queries can be expressed. Writing queries when WCF Data Service is used is not so attractive - requires string expressions such as:

.AddQueryOption("$filter", "Id eq 100");
like image 1
vajanko Avatar answered Oct 07 '22 03:10

vajanko