TDD 和 MVC 的十字路口。什么 ORM 集成得很好?
我刚刚开始接触 MVC 世界,并且使用了 VS 2010 中内置的标准 MVC 模板。我已经连接了几个控制器和视图,现在我需要访问我的数据库。
我有一个现有的 SQL Server 2005 数据库,该数据库非常大,已经由第三方公司定义。我正在尝试为其添加一个报告/管理界面以满足我们公司的特定需求。
所以,我想最初只是从这个数据库的几个表中提取一个列表。那么...使用 MVC 3,有哪些可以很好集成的 ORM 工具?
我还尝试使用试驾设计方法。我不确定如何进行需要插入/更新/删除数据的测试。这是“Mocks”发挥作用吗?
I'm just starting out in MVC world, and I've used a standard MVC template that's built into VS 2010. I've got a couple of controllers and views hooked up, and now I need to get to my database.
I've got an existing SQL Server 2005 database that is quite large, already defined by a 3rd party company. I'm trying to bolt on a reporting/admin interface to it for our specific company needs.
So, I'd like, initially to just pull a list of things out of a few tables from this DB. So...using MVC 3, what are some ORM tools that integrate nicely?
I'm also trying to use a Test Drive Design approach. I'm not sure what to do for tests that would require insert/update/delete of data. Is that were "Mocks" come into play?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每个 ORM 都与 Asp.net MVC 很好地集成。 ASP.NET MVC 中没有任何东西会使 ORM 集成变得困难。
您最大的障碍是使用旧数据库。 NHibernate 和 Entity Framework 4 是我所知道的唯一两个可以很好地映射到遗留数据库的免费 ORM。 EF4 在映射到遗留数据库方面并不算太差,它只是更适合全新开发。相比之下,NHibernate 几乎可以映射您能想到的任何场景。
测试的难易程度主要取决于使用哪种数据访问模式。存储库模式很受欢迎,因为它易于测试。不需要嘲笑。
Every ORM integrates nicely with Asp.net MVC. There is nothing in asp.net mvc that would make ORM integration hard.
Your biggest hurdle is using a legacy database. NHibernate and Entity Framework 4 are the only two free ORMs I'm aware of that map to legacy databases well. EF4 isn't too bad at mapping to legacy databases it just works better with green field development. In contrast NHibernate can map almost any scenario you can think of.
Testing ease is going to be mostly dependent on which data access pattern to use. The Repository pattern is popular because of how friendly it is to test with. No mocking is required.
我强烈建议您使用 Castle 组件:Windsor、Dynamic Proxy 和 Active Record。
您基本上可以模拟数据,因为 Active Record 创建的模型具有允许您手动或通过动态代理的拦截器操作它的属性。
打包存储库和数据服务,以更好地控制您的数据访问。
在适用的情况下使用规范模式以轻松实现灵活查询。
在数据服务中将 Linq 与 Active Record 结合使用,以便能够传递
IEnumerable
或规范(可能会也可能不会包装 NHibernate 的抽象条件并将其转换为DetachedCriteria
) code> 或可能包含DetachedCriteria
或 HQL 或您封装的任何内容)作为查询。这样您就可以轻松模拟数据库访问并更轻松地重构和测试。
I strongly suggest you to use the Castle components: Windsor, Dynamic Proxy and Active Record.
You can basically mock the data since Active Record creates a model with attributes that allow you to manipulate it manually or through Dynamic Proxy's interceptors.
Wrap up repositories and data services to gain more control of your data access.
Use the specifition pattern where applicable to allow flexiable querying easily.
Use Linq with Active Record in your data services in order to be able to pass
IEnumerable<T>
or specifications (that may or may not wrap NHibernate's abstract criteria and convert them to aDetachedCriteria
or may contain theDetachedCriteria
or an HQL or whatever you are encapsuling) as queries.That way you can mock your database access easily and refactor and test more easily.