的NerdDinner MVC4版本 - 为什么他们删除该资源库类? [英] NerdDinner MVC4 version - why did they delete the repository classes?

查看:233
本文介绍了的NerdDinner MVC4版本 - 为什么他们删除该资源库类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经检查出的NerdDinner教程。我是通过原始的PDF阅读教程( http://aspnetmvcbook.s3.amazonaws.com/ aspnetmvc-nerdinner_v1.pdf )使用LINQ to SQL和MVC2。在这个教程中,他们实现数据的上下文,然后实现库类与数据实体交互。

I've been checking out the NerdDinner tutorials. I was reading through the original PDF tutorial (http://aspnetmvcbook.s3.amazonaws.com/aspnetmvc-nerdinner_v1.pdf) that uses LINQ to SQL and MVC2. In that tutorial, they implement a data context and then implement repository classes to interact with the data entities.

我看到该项目被更新为使用MVC4和Entity Framework( HTTP://nerddinner.$c$cplex .COM ),所以我通过code浏览,看看有什么变化,他们会实现的。他们改变了项目为code-首先对每个数据实体单独的模型类。我很惊讶地看到,他们摆脱了存储库的完全。

I saw the project was updated to use MVC4 and Entity Framework (http://nerddinner.codeplex.com) so I browsed through that code to see what changes they'd implemented. They changed the project to be code-first with separate model classes for each data entity. I was surprised to see that they got rid of the repositories completely.

我认为这是比较好的做法是通过存储库模式与数据库抽象通信......我知道教程往往做出错误的选择,设计为简洁起见,但我不知道为什么已经实施库教程做出从这个版本忽略它们的决定。

I thought it was generally good practice to abstract communication with the database through the repository pattern... I know tutorials often make poor design choices for the sake of brevity, but I'm wondering why a tutorial that had already implemented repositories made the decision to omit them from this version.

有什么在MVC4或EF使仓库过时/冗余?

Is there something in MVC4 or EF that makes repositories obsolete/redundant?

推荐答案

有上是否有意义的仓库包装等先进的抽象,如实体框架经过长时间的辩论。

There is a long debate on whether it makes sense to wrap such advanced abstractions like the Entity Framework in repositories.

从历史上看,资源库是伟大的。这是安全的,有额外的抽象层,只是为了能够在不同数据提供者之间切换,普通的老式的DataSet S,文件,LINQ,等等。

Historically, repositories were great. It was safe to have an extra layer of abstraction just to be able to switch between different data providers, plain old DataSets, files, linq, whatever.

然而,许多EF纯粹主义者声称,EF已经是单位的工作和库与数据上下文是工作单位和dbsets是仓库的抽象。他们声称,LINQ是一种查询语言不够好抽象,你不需要特定的,有限制的API。

However, many EF purists claim that EF is already an abstraction of the unit-of-work and repository with the data context being the unit of work and dbsets being repositories. They claim that the LINQ is the good enough abstraction of a query language and you don't need specific, restricted APIs.

也有人说,这是不是安全地假定所有可能的供应商都在他们提供同样的LINQ查询结果一致感兼容。一些供应商可能会受到限制,甚至拒绝评估具体的查询。这 - 人们说 - 意味着你还需要一个抽象的 EF,让你保证高层相同的数据合约

Others say that this is not safe to assume that all possible providers are compatible in a sense that they provide consistent results for the same LINQ queries. Some providers could be limited and even refuse to evaluate specific queries. This - the people say - means that you still need an abstraction over EF so that you guarantee the same data contract for higher layers.

如果有人决定取消从实例库层,这是可能的原因有两个原因之一:

If someone decided to remove the repository layer from the example, this is possibly because of one of two reasons:


  • 有人意识到,仓库只是让这个例子更复杂,拆除它们简单

  • 的人谁是EF纯粹想提倡一个事实,即任何规定不得站在上面EF

我个人喜欢库和尽可能使用它们。

Personally, I like repositories and use them whenever possible.

这篇关于的NerdDinner MVC4版本 - 为什么他们删除该资源库类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆