工作单位的效益和信息库模式与实体框架

编程入门 行业动态 更新时间:2024-10-27 02:29:58
本文介绍了工作单位的效益和信息库模式与实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

据MSDN,的DbContext被定义为

According to MSDN, DbContext is defined as

重presents单位-OF-工作和库的模式的组合,使您能够查询数据库,并组合在一起的将被写回到店里为单位的变化。

"Represents a combination of the Unit-Of-Work and Repository patterns and enables you to query a database and group together changes that will then be written back to the store as a unit."

我想知道的DbContext已经申请Unit_Of,工作和库的模式,那么为什么asp教程,并发现所有在互联网上的例子进一步对的DbContext应用这些彭定康像this tutotial。这难道不是一些东西,已经实施的执行?如果它不是那么什么是使用单位-OF-工作和库模式进一步上的DbContext(除非将它们用在测试项目)?

I want to know if DBContext is already applying Unit_Of-Work and Repository pattern then why does asp tutorial and all the examples found over the internet apply these patten further on the DBContext like given in this tutotial. Isn't this the implementation of something which is already implemented? If it isn't then what is the benefit of using Unit-Of-Work and Repository patterns further on DBContext (except using them in Test project)?

推荐答案

是的,的DbContext重新presents一个的UnitOfWork并DbSet重新preseets存储库,但人们往往甚至创建一个抽象了那些因为某些原因:

Yes, DbContext represents a UnitOfWork and DbSet represeets a Repository but people tend to even create an abstraction over those for some reasons:

  • 也许他们不希望自己的项目紧密结合,以实体框架和架构,使它们隐藏起来这些抽象的背后,使他们能够取代EF任何其他的ORM没有任何修改的数据访问层的界面。
  • 在他们使用的存储库其他时候要分清楚哪些操作是允许对某些实体的(如CustomerRepository允许添加和更新客户,但不删除它们)的。在另一方面,它可以让客户端开发人员很容易地识别可用的操作的某些实体,换句话说,它们创建储存库命名约定和接口,这是与域语言兼容。
  • 在移动数据库相关的操作库,您可以拦截这些行动并进行日志记录,性能调整或所需的任何其他操作。
  • 在某些这样做是为了使测试更加简单,说我有3种方法的ICustomerRepository接口,那么我可以很容易地嘲笑嘲笑的IDbSet有很多很多方法,高达代替。
  • 有人不要不可以甚至创建了一个抽象了的DbContext 和 DbSet ,他们只需直接使用它们,这是完全有效的做到这一点。
  • Maybe they don't want their project tightly coupled to entity framework and its architecture so they hide them behind those abstractions so they can substitute EF for any other ORM without any modification to the interface of the data access layer.
  • Other times they use repositories to make it clear which operations are allowed for certain entities, (e.g. CustomerRepository allows adding and updating customers but not deleting them). On the other hand, it lets client developer easily recognize available operations for certain entities, in other words they create repositories with naming conventions and interface that is compatible with the domain language.
  • Moving db related operations to repositories allows you to intercept those operations and perform logging, performance tuning or any other operation you want.
  • Some do it to make testing easier, say i have an ICustomerRepository interface with 3 methods then i can easily mock that up instead of mocking an IDbSet with many many methods.
  • Some people don not even create an abstraction over DbContext and DbSet, they just use them directly and it is perfectly valid to do so.

更多推荐

工作单位的效益和信息库模式与实体框架

本文发布于:2023-11-06 22:24:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564837.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:信息库   实体   框架   效益   单位

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!