Hubertus (2) [Avatar] Offline
#1
Hi

We are having some issues with deciding how to deliver LINQ query results over a network. Our system will be a proprietary data server (nothing to do with SQL server or any RDBMS) that supports its own customized versions of various LINQ operators.

We want to have clients that can send a request to the server to execute a specified query (akin to say a stored procedure), this will just be some compiled method that runs a LINQ query on the data, and will return (generally) an IEnumerable<SomeAnonymousType>.

The client will want to assign the result to say a DataGridView or similar.

The client does NOT have any LINQ query coded locally and does NOT have or know any of the classes used in the query.

So many examples and articles extol the flexibility of LINQ, yet none of them address this issue and those that do always blindly assume one is using SQL Server and has all the ADO stuff to go with it.

How does one enable a simple client app to get at the results of arbitrary LINQ queries that are executed on a remote server?

We have succeeded in devising a protocol that allows the client to "get at" the anonymous types used in the remote query and we can return these and the client can even "see" the results as-if the query had been run locally.

However we do not want to focus on this if there is some other simple option out there for doing this.

Any info much appreciated.

H
fabrice.marguerie (224) [Avatar] Offline
#2
Re: Transfer query results over a network.
Hi,

In order to keep things simple, I would create concrete types (custom classes that you declare on the server side) and then use WCF to return the results (arrays of instances of your custom classes) over the network. Through a WCF proxy, the client will be able to use your custom classes.
This is a classic approach for which you will find a lot of information on the web or in books.

If you prefer a more dynamic approach, you can return untyped DataSets. This would allow you to return tabular data with dynamically defined schemas.
LINQ to DataSet can help you to achieve this. See chapter 14.

Fabrice
Hubertus (2) [Avatar] Offline
#3
Re: Transfer query results over a network.
Hi Fabrice

I will explore your suggestion, thanks for the help on this. May I ask, with the WCF proposal that you envisage, is there not the same 'serialize' issue?

As you know, the query results are often composed of various anonymous types and these are not serializable, would a WCF approach overcome this?

Our experiemtal proof-of-concept code here, allows us to repackage the query results (removing the anonymous types) serialize the data (our classes are serializable) along with the 'Type' for ever type, including the anonymous types.

The client deserialzies this, then repacks the results by instantiating new instances of the original anonymous types, if it gets AssemblyResolve events it requests the assembly from the server which has a dedicated channel for this.

The end result is that the client sees pretty much the original query result, anonymous types and all, as-if the query had been coded and executed locally.

My issues is, is that a waste of effort or is this something we should refine and stick with, since it does seem to solve the problem in a new way.

Thx
H
fabrice.marguerie (224) [Avatar] Offline
#4
Re: Transfer query results over a network.
If you want to stick to anonymous types, I don't think that WCF can help you per se. I guess you'll have to go on with your own solution, as you did with your proof-of-concept code.