使用 Linq 表达式将客户端与 DAL(服务器端)解耦

发布于 2024-07-26 02:58:13 字数 536 浏览 2 评论 0原文

我在 Linq 上的许多帖子中找不到答案,所以我在这里。 我们有一个客户端-服务器应用程序,其中客户端完全不知道服务器端的实际 DAL,而服务器端是使用 NHibernate 偶然实现的。 这意味着,客户端程序集没有对 NHibernate 的引用,也没有数据库抽象。 客户端严格用实体术语来表述,实体是基于CSLA业务对象的。

我想让客户端过滤显示的实体。 我的想法是让客户端构造一个Linq表达式,将其传输到服务器端,使用Linq to NHibernate获取与表达式匹配的数据并将其返回给客户端。

我已经下载并编译了 Linq to NHibernate,但不幸的是我找不到将 Linq 表达式(也称为客户端)与相应的 NHibernateContext 实例(又称为服务器端)解耦的示例。 所有示例似乎都类似于

from c in db.Customers where ...

一个语句中的上下文 (db.Customers) 和表达式 (where ...)。

是否可以将它们解耦? 谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

若水般的淡然安静女子 2024-08-02 02:58:13

看看这篇文章。 您可以使用此概念传递查询参数,然后动态构建查询。

foreach 循环中内置的 Linq 查询始终从上次迭代中获取参数值

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

梦情居士 2024-08-02 02:58:13

事实证明这非常简单 - from c in db.Customers where linq-exp select c 相当于 db.Customers.Where(linq-exp)

我实际上需要将此作为更广泛问题的一部分 - 在客户端指定 linq 表达式并使用它在服务器端获取数据。 我的帖子 这里更详细地描述了它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文