简体   繁体   中英

Using Linq Expressions to decouple client side from DAL (which is server side)

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 ...

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

Is it possible to decouple them? Thanks.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM