views:

210

answers:

2

Hi folks. I could not find the answer amongst the many posts on Linq, so here I am. We have a client-server application, where the client side has absolutely no knowledge of the actual DAL on the server side, which is incidentally implemented using NHibernate. Meaning, there is no references to NHibernate from the client side assemblies, as well as no database abstraction. Client side speaks strictly in the terms of entities, which are based on CSLA business objects.

I would like to let the client side filter the displayed entities. My idea is to let the client side construct a Linq expression, transmit it to the server side, fetch the data matching the expression using Linq to NHibernate and return it back to the client.

I have downloaded and compiled Linq to NHibernate, but unfortunately I cannot find an example which decouples Linq expressions (aka client side) from the respective NHibernateContext instance (aka server side). All the examples seem to be like

from c in db.Customers where ...

i.e. both the context (db.Customers) and the expression (where ...) in one statement.

Is it possible to decouple them? Thanks.

A: 

Take a look at this post. You could use this concept to pass in query parameters and then dynamically build your query.

http://stackoverflow.com/questions/295593/linq-query-built-in-foreach-loop-always-takes-parameter-value-from-last-iteration

Andrew Siemer
Hi Andrew. I visited the link. But all the samples there bind the context and the expression together in one linq statement. I need something like this:var expr = GetExpressionFromUser(); // <-- on the client sidevar results = FetchByExpression<T>(expr); // <-- on the server side
mark
A: 

This turns out to be pretty easy - from c in db.Customers where linq-exp select c is equivalent to db.Customers.Where(linq-exp).

I have actually needed this as part of a broader issue - specifying a linq expression on the client side and use it to fetch data on the server side. My post here describes it at more details.

mark