开沟的ActiveRecord和NHibernate - 如何重新构建? [英] Ditching ActiveRecord and NHibernate -- how to rearchitect?

查看:140
本文介绍了开沟的ActiveRecord和NHibernate - 如何重新构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC3的NHibernate / ActiveRecord的项目。该项目打算好了,而且我变得有点用我的模型对象(大多是三四类的巨头层次)。

I have an MVC3 NHibernate/ActiveRecord project. The project is going okay, and I'm getting a bit of use out of my model objects (mostly one giant hierarchy of three or four classes).

我的应用程序是基于分析;我存储分层数据,后来切片起来,在图等显示出来,因此实际的关系并不复杂。

My application is analytics based; I store hierarchial data, and later slice it up, display it in graphs, etc. so the actual relationship is not that complicated.

到目前为止,我还没有太大的ORM受益;它使查询容易(ActiveRecord的),但我经常需要比全对象更少的信息,我需要写通过对集合复杂和多选择和迭代硬查询 - 原始的SQL会更快,更清洁。

So far, I haven't benefited much from ORM; it makes querying easy (ActiveRecord), but I frequently need less information than full objects, and I need to write "hard" queries through complex and multiple selects and iterations over collections -- raw SQL would be much faster and cleaner.

所以,我想在这种情况下开沟的O​​RM,并回到原始的SQL。但我不知道如何重新构建我的解决方案。我应该如何处理数据库层?

So I'm thinking about ditching ORM in this case, and going back to raw SQL. But I'm not sure how to rearchitect my solution. How should I handle the database tier?


  • 如果我还有每个模型一个类,用静态方法来查询的对象?或者我应该有一个重类presenting数据库?

  • 我应该写的ActiveRecord(或我自己的ActiveRecord的般的实现)在我自己的层保留现有的code或多或少的声音?

  • 我要结合ORM方法(如保存/删除)到我的模型类或不?

  • 我应该改变我的表结构(每类一表的所有字段)?

任何意见将是AP preciated。我试图找出最佳的架构和设计一起去。

Any advice would be appreciated. I'm trying to figure out the best architecture and design to go with.

推荐答案

许多人,包括我自己,认为ActiveRecord的模式是一个反模式,主要是因为它打破了SRP和不允许POCO对象(域紧密耦合到一个特定的ORM)。

Many, including myself, think the ActiveRecord pattern is an anti-pattern mainly because it breaks the SRP and doesn't allow POCO objects (tightly coupling your domain to a particular ORM).

在说,你不能击败了简单的CRUD的东西一个ORM,所以我会保持某种ORM的周围那种工作。刚刚重新设计你的应用程序中使用POCO对象和某种或与您的ORM实现细节存储库模式的另一个项目。

In saying that, you can't beat an ORM for simple CRUD stuff, so I would keep some kind of ORM around for that kind of work. Just re-architect your application to use POCO objects and some kind or repository pattern with your ORM implementation specifics in another project.

至于你的硬的疑问,我会考虑使用一个微小的ORM(如小巧玲珑 PetaPoco ,或的海量),用自己的原始SQL查询的对象。

As for your "hard" queries, I would consider creating one class per view using a tiny ORM (like Dapper, PetaPoco, or Massive), to query the objects with your own raw sql.

这篇关于开沟的ActiveRecord和NHibernate - 如何重新构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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