如何将 LINQ-to-SQL 映射到 BLL 类?

发布于 2024-08-04 01:11:23 字数 234 浏览 4 评论 0原文

我正在考虑使用 LINQ-to-SQL 在我的应用程序中创建 DAL。我通常手动创建 DAL,因为我不太喜欢 ORM(在我看来,太多抽象),但我试图为不耐烦的客户节省一些时间。

我的问题是,如何将 LINQ-to-SQL 生成的类映射到 BLL 类?您是否只是将代码添加到 LINQ-to-SQL 生成的类(它们是部分类)并且根本不创建 BLL 类(因此该类同时作为 DAL 和 BLL 类工作)或者您通常如何做它?

谢谢

I'm considering using LINQ-to-SQL for creating the DAL in my app. I normally create the DAL manually as I'm not a big fan of ORM (too much abstraction IMO) but I'm trying to save some time for an impatient client.

My question is, how do you map the classes generated by LINQ-to-SQL to your BLL classes? Do you just add your code to the classes generated by LINQ-to-SQL (they are partial classes) and don't create BLL classes at all (so the class work as both a DAL and BLL class) or how do you normally do it?

Thanks

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

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

发布评论

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

评论(1

风吹过旳痕迹 2024-08-11 01:11:23

重要的区别是认识到 LINQ to SQL 实际上有两个部分:您拥有的实体类(它们在您的解决方案中生成或手写)以及 LINQ to SQL 库,该库负责将 LINQ 表达式转换为 SQL 的繁重工作并预测结果。前者是你的BLL,后者是你的DAL。 LINQ to SQL 模型主要满足这一点,因为 DAL 与实体无关(或与 BLL 无关);并且您的实体与 DAL 的耦合非常松散;如有必要,它们可以完全脱离 DAL 使用。

因此,简短的回答是 LINQ to SQL 模型可以同时满足 DAL 和 BLL 角色,但仅仅因为您对这两个角色使用一种模型并不意味着您不恰当地组合了这两层。

The important distinction is recognizing that LINQ to SQL actually has two parts: the entity classes which you own - they are either generated or hand-written in your solution - and the LINQ to SQL libraries which do the heavy lifting of translating LINQ expressions into SQL and projecting the results. The former is your BLL, and the latter is your DAL. The LINQ to SQL model mostly fulfills this, as the DAL is entity-agnostic (or BLL-agnostic); and your entities have very loose couplings to the DAL; they can be used apart from the DAL entirely if necessary.

So, the short answer is the LINQ to SQL model can fulfill both the DAL and BLL roles, but just because you're using one model for both doesn't mean you're combining the two layers inappropriately.

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