三层最佳实践 - 表示层中的 LinqTOSQL 访问

发布于 2024-09-30 17:12:41 字数 268 浏览 1 评论 0原文

设想: 我有一个包含表示层(ASP.NET)、业务逻辑层(dll)和数据层(dll)的场景,后者有一个 LinqTOSQL DataContext 文件(dbml),它保存特定数据库的表和存储过程。项目之间的链接是:

依赖关系: 业务逻辑层有数据层的参考 表示层有业务逻辑层的参考

我的问题: 问题是,我有时需要返回与数据上下文对应的表类型的对象,但由于表示层没有对数据层的引用,我无法使用表对象...是吗?直接在表示层中引用数据层的好习惯?或者有人可以指导我如何从表示层实现表格的最佳方法

Scenario:
I have a scenario with a Presentation layer (ASP.NET), Business Logic Layer (dll) and Data Layer(dll) in the latter there is a LinqTOSQL DataContext file (dbml) which holds tables and stored proc for a particular database. The linking between projects are:

Dependencies:
Business Logic Layer has a reference for Data Layer
Presentation Layer has a reference for Business Logic Layer

My Problem:
The problem is that I have cases when I need to return an object of a table type corresponding to the datacontext, but since the Presentation Layer does not has a reference to the Data Layer I can't use the table object...Is it good practice to reference the Data Layer directly in the Presentation Layer? Or could someone guide me to the best way how I could achieve the Tables from the Presentation Layer

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

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

发布评论

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

评论(1

甜`诱少女 2024-10-07 17:12:41

不要让业务逻辑层返回 System.Data.Linq.Table到表示层,而是让它返回 System.Table到表示层。 Collections.Generic.IEnumerable通过隐式转换,或通过调用 System.Collections.Generic.IList >ToList() 在桌子上。

听起来 dbml 文件中定义的对象已经在您的域命名空间中,因此这样您就不必在表示层中引用 System.Data.Linq

Instead of having the business logic layer return a System.Data.Linq.Table<TEntity> to the presentation layer, have it return a System.Collections.Generic.IEnumerable<TEntity> via implicit cast, or a System.Collections.Generic.IList<TEntity> by calling ToList() on the table.

It sounds like the objects defined in your dbml file are already in your domain namespace, so this way you don't have to reference System.Data.Linq in your presentation layer.

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