Question

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.

Was it helpful?

Solution 2

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.

OTHER TIPS

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

Linq query built in foreach loop always takes parameter value from last iteration

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top