简体   繁体   English

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

[英]Entity Framework in a n tiered architecture - Best Practices to follow?

I have been reading the MSDN article at http://msdn.microsoft.com/en-us/magazine/cc700340.aspx 我已经在http://msdn.microsoft.com/zh-cn/magazine/cc700340.aspx上阅读了MSDN文章。

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. 但是,我想知道在asp.net n分层应用程序中使用实体框架(.net framework 3.5 sp1)是否有其他/替代最佳实践。

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. 我认为与实体框架一起使用的常见设计模式是存储库模式,我不会提供链接,因为Google搜索将返回比我可以在此处发布的内容更多的链接。 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. 如果您使用的是标准ASP.NET,那么我建议您使用链接的文章中建议的MVP模式,以帮助您分离问题并创建可测试的代码。 However if you're using ASP.NET MVC then MVP is irrelevant as the framework helps separate your concerns for you. 但是,如果您使用的是ASP.NET MVC,则MVP无关紧要,因为该框架可帮助您分离问题。 A little more background on your environment might help make recommendations. 稍微了解一下您的环境可能有助于提出建议。

It's worth noting that this is an area that's had a lot of attention as part of .NET 4 and EF4. 值得注意的是,作为.NET 4和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). 他们现在支持POCO以及自跟踪实体,两者都可以在层和层(包括WCF边界)之间来回发送。

Take a look at this blog entry about Self-Tracking-Entities for more information. 请参阅有关自我跟踪实体的博客条目 ,以获取更多信息。

I like to use the UnitOfWork pattern along with DDD and a service layer. 我喜欢将UnitOfWork模式与DDD和服务层一起使用。 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. 服务层使用适配器模式或远程外观模式将dto对象传递给其客户端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM