分层架构中的实体框架 - 要遵循的最佳实践?

发布于 2024-08-13 16:29:54 字数 245 浏览 1 评论 0原文

我一直在阅读 MSDN 文章 http://msdn.microsoft.com/en-us/magazine/cc700340。 aspx

但想知道是否有其他/替代最佳实践在 asp.net 分层应用程序中使用实体框架(.net Framework 3.5 sp1)。

I have been reading the MSDN article at
http://msdn.microsoft.com/en-us/magazine/cc700340.aspx

But was wondering if there are other / alternatives best practices to using the Entity Framework (.net framework 3.5 sp1) in an asp.net , n tiered application.

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

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

发布评论

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

评论(3

你的背包 2024-08-20 16:29:54

我认为与实体框架一起使用的常见设计模式是存储库模式,我不会提供链接,因为谷歌搜索将返回的内容超出了我在此处发布的内容。它将帮助您将数据访问代码隐藏在接口后面,以便更轻松地进行测试和关注点分离。

我认为您在最佳实践方面所做的任何选择将在很大程度上取决于您正在使用的工具。如果您使用标准 ASP.NET,那么我建议您使用链接到的文章中建议的 MVP 模式,以帮助您分离您的关注点并创建可测试的代码。但是,如果您使用 ASP.NET MVC,那么 MVP 就无关紧要了,因为该框架可以帮助您分离您的关注点。了解更多有关您的环境的背景可能有助于提出建议。

I think that a common design pattern used with the entity framework is the Repository pattern, I won't provide links because a google search will return more than I can post here. It will help you hide your data access code behind an interface that allows for easier testing and separation of concerns.

I think that any choices you make in terms of best practice will depend heavily on the tools you're working with. if you're using standard ASP.NET then I would suggest going with the MVP pattern suggested in the article you linked to to help you separate your concerns and create testable code. However if you're using ASP.NET MVC then MVP is irrelevant as the framework helps separate your concerns for you. A little more background on your environment might help make recommendations.

聚集的泪 2024-08-20 16:29:54

值得注意的是,作为 .NET 4 和 EF4 的一部分,这是一个备受关注的领域。

他们现在支持 POCO 以及自我跟踪实体,两者都可以在层和层(包括 WCF 边界)之间来回发送。

看看 这篇关于自我跟踪实体的博客文章了解更多信息。

It's worth noting that this is an area that's had a lot of attention as part of .NET 4 and EF4.

They now have support for POCOs, as well as Self-Tracking-Entities, both of which can be sent back and forth between layers and tiers (including WCF boundaries).

Take a look at this blog entry about Self-Tracking-Entities for more information.

指尖微凉心微凉 2024-08-20 16:29:54

我喜欢将 UnitOfWork 模式与 DDD 和服务层一起使用。我不会将域对象传递到服务层以外的任何层。即使这样,我的领域对象也是通过接口抽象的。服务层使用适配器模式或远程外观模式将 dto 对象传递给其客户端。

I like to use the UnitOfWork pattern along with DDD and a service layer. I do not pass my domain objects to any layer other than the service layer. Even then my domain objects are abstracted by interfaces. The service layer uses an adapter pattern or remote facade pattern to pass dto objects to its clients.

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