可持续无知量表? [英] Can Persistence Ignorance Scale?

查看:158
本文介绍了可持续无知量表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在简要地看看NHibernate和Linq2Sql。我也打算去看实体框架。



当我谈到这些ORM的时候,提出的问题是他们不能缩放,所以可以吗从Google获得的印象可以很好地扩展,但是最终我认为必须付出代价,是否值得为更简单的业务层付出代价。

解决方案

这是一个很好的问题,而IMHO他们可以像任何自定义的DAL一样扩展。我只使用nHibernate,所以我只会专注于它和它有助于扩展系统的功能。




  • Lazy Loading - 由于它支持延迟加载,您可以避免加载任何不合适的项目。当然,您需要注意选择n + 1问题,但是系统中有一些事情可以防止这种情况。

  • 渴望获取 - 有各种各样的方式来热切地获取可能的对象需要允许您避免额外的SQL访问。

  • 二级缓存 - nHibernate支持二级缓存,可以通过减少到DB的行程来增加可扩展性。可以使用各种备份提供程序,为您提供一些灵活性。

  • 编写自己的SQL - 在nHibernate中,您可以调用存储过程,或者内联提供将返回您的实体的SQL查询。当生成的sql不剪切时,这将允许您使用自己的SQL。例如,使用递归查询加载自加入树。



现在,我认为最初调整一个自定义DAL层,因为你的建筑是亲密的,可以微调它;然而,一个好的ORM将提供大量的钩子,使您可以优化相当多的。你只需要花一些时间学习。



我也觉得如果你有一个性能关键的代码区域,你不能让你的ORM在你的要求那么你应用程序的那个微小区域就可以自定义构建自己的DAL层。如果您正在使用像工厂创建的Repository这样体面的设计模式,那么您需要做的就是转换存储库的实现。


I've been having a brief look at NHibernate and Linq2Sql. I'm also intending to have a peek at Entity Framework.

The question that gets raised, when I talk of these ORM's is "They can't scale", so can they? From Google I get the impression they're able to scale well, but ultimately I suppose there must be a price to pay, Is it worth paying for a richer simpler business layer.

解决方案

This is a good question, and IMHO they can scale just as well as any custom DAL. I've only used nHibernate so I will focus only on it and the features it has which can help scale a system.

  • Lazy Loading - Since it supports lazy loading you can avoid loading any unnessecary items. Of course you need to watch out for the Select n+1 problem however there are things in the system to prevent this.
  • Eager Fetching - There are various ways to eagerly fetch objects which you might need allowing you to avoid extra trips to SQL.
  • Second Level Cache - nHibernate has support for a second level cache which can be used to increase the scalability by reducing trips to the DB. There are various backing providers available which give you some flexibility.
  • Write your own SQL - In nHibernate you can call stored procedures, or provide the SQL query inline that will return your entities. This will let you use your own SQL when the generated sql doesn't cut it. For example eager loading a self joining tree using a recursive query.

Now with that said, I think it is easier to initially tweak a custom DAL layer because your are intimate with its construction and can fine tune it; however, a good ORM will provide plenty of hooks that allow you to optimize quite a bit. You just need to spend some time learning it.

I also feel that if you have a performance critical area of code and you can't get your ORM to work within your requirements then for that tiny area of your application you can custom build your own DAL layer. If you're using a decent design pattern such as a Repository created by a factory, then all you need to do is swap out the implementation of your repository

这篇关于可持续无知量表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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