Linq2SQL,实体:中间层或数据访问层

发布于 2024-09-04 05:59:28 字数 147 浏览 2 评论 0原文

各位,

在标准的 3 层架构中,您会将 Linq2SQL dbml 文件放在哪里?

对于 ado.net 实体数据模型,您的答案是否相同?

如果dbml文件在中间层,那么你有数据层吗?

问候,

布雷特

Folks,

In a standard 3-tier architecture, where would you put your Linq2SQL dbml file?

Is your answer the same for a ado.net entity data model?

If the dbml file is in the middle tier, then do you have a data layer?

Regards,

Brett

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

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

发布评论

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

评论(2

生活了然无味 2024-09-11 05:59:28

DBML 确实位于中间层。 LINQ to SQL 查询数据层(您的 SQL Server 数据库)。 LINQ to SQL 通常位于中间层的底层,并且您不会通过线路发送 LINQ to SQL 实体(它们不能很好地序列化)。

使用实体框架,您的架构看起来非常相似,只是 EF 允许通过线路发送域对象。尤其是随着与 EF 良好集成的新技术(如 OData)的出现。

The DBML would indeed be in the middle tier. LINQ to SQL queries the data tier (your SQL Server database). LINQ to SQL would normally be in the bottom layer of the middle tier and you would not send LINQ to SQL entities over the wire (they don't serialize well).

With Entity Framework your architecture looks a lot alike, except that EF allows domain objects to be sent over the wire. Especially with new technologies (like OData) coming out that integrate well with EF.

原来分手还会想你 2024-09-11 05:59:28

DBML 应该是数据层的一部分,而不是直接暴露给业务层。相反,最好公开获取和保存实体的方法,并保持与持久性细节的交互(在本例中是 Linq2Sql,但通过抽象它,您可以稍后更改为 Linq2Entities 或其他任何内容,而不会破坏您的应用程序)。

如果需要执行多个查询并稍微操作数据来创建实体,或者在保存时做额外的工作(处理子表的外键等),这也是一个很好的模型,因为它可以隐藏这些详细信息其他层。

关于 Steven 关于 L2Sql 序列化不好的评论,不幸的是,如果您使用 Linq2Sql 的构建器为您提供的开箱即用的内容,那么这就是事实。不过,部分类中的一些解决方法可以很容易地解决这个问题。

the DBML should be part of the Data Layer, and not directly exposed to the Business Layer. Instead it's best to expose methods for Getting and Saving entities, and keep the interaction with the specifics of persistence kept under the covers (in this case it's Linq2Sql, but by abstracting it, you can later change to Linq2Entities, or anything else without breaking your app).

this is also a good model if it necessary to perform multiple queries and manipulate the data a bit to create your entities, or do extra work when saving (dealing with foreign keys for child tables, etc.) in that it keeps those details hidden from the other tiers.

regarding Steven's comments about L2Sql not serializing well, it's unfortunately true if you use what Linq2Sql's builder gives you out of the box. a few workarounds in partial classes cleans that up easily enough, though.

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