我怎样才能解决这个NHibernate的查询在N层架构? [英] How can I solve this NHibernate Querying in an n-tier architecture?

查看:135
本文介绍了我怎样才能解决这个NHibernate的查询在N层架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经打了一个墙试图从我的业务层分离NHibernate的。我的架构是这样的:

I've hit a wall with trying to decouple NHibernate from my services layer. My architecture looks like this:

网络 - >服务 - >资料库 - > NHibernate的 - > DB

web -> services -> repositories -> nhibernate -> db

我希望能够从我的服务层,可能是我的web层产卵NHibernate的查询,而这些层知道什么ORM他们正在处理。目前,我有我的所有库的查找方法,在需要的IList<对象[]>标准。这让我在一个标准列表通诸如新的对象(){用户名,usernameVariable}; 在我的建筑的任何地方。 NHibernate的需要这一点,并创建一个新的标准对象,并在标准通过补充道。这工作正常从我的服务层基本的搜索,但我想在我的存储库转换成一个标准的NHibernate的查询对象传递的能力。

I want to be able to spawn nhibernate queries from my services layer and possibly my web layer without those layers knowing what orm they are dealing with. Currently, I have a find method on all of my repositories that takes in IList<object[]> criteria. This allows me to pass in a list of criteria such as new object() {"Username", usernameVariable}; from anywhere in my architecture. NHibernate takes this in and creates a new Criteria object and adds in the passed in criteria. This works fine for basic searches from my service layer, but I would like to have the ability to pass in a query object that my repository translates into an NHibernate Criteria.

说真的,我很想实现像什么在这个问题描述:<一href=\"http://stackoverflow.com/questions/8812441/is-there-value-in-abstracting-nhibernate-criterion\">Is在抽象NHibernate的标准存在的价值。我只是没有找到关于如何实现这样的事情任何好的资源。是方法在这个问题一个很好的方法描述?如果是这样,任何人都可以提供关于如何实现这样的解决方案的一些指点?

Really, I would love to implement something like what is described in this question: Is there value in abstracting nhibernate criterion. I'm just not finding any good resources on how to implement something like this. Is the method described in that question a good approach? If so, could anyone provide some pointers on how to implement such a solution?

推荐答案

抽象掉的ORM将:


  • 带来了很多重新定义的工作,它的API

  • 请就不可能优化/批数据库访问

  • 请了很多困难,了解执行哪些查询

  • 将导致吨SELECT N + 1

和所有价值很小:模糊选项交换ORM框架,将最有可能有很多其他的问题。

and all for very little value: the vague option to exchange the ORM framework which will most probably have a lot of other problems


  • 缺少的功能

  • 在实现微妙的差异

  • 学习

更新:经验

我曾经参与执行现有的DAL抽象的新供应商。它结束了表演得厉害,推出了很多的bug,ErrorHandling中得一塌糊涂,有时使用陈旧的数据,因为应用程序采用默认的实现。原因:

I was once involved in implementing a new provider of an existing DAL abstraction. It ended up performing badly, introduced a lot of bugs, Errorhandling was a mess and sometimes used stale data because the application assumed the default implementation. Reasons:


  • 缓存不知道背景

  • Cacheimlementation有不同的语义

  • 配料API的差别太大,被抽象

  • 错误是特定于实现(例如 FileNotFound - > FilesearchDialog 的是一个基于TCP / IP数据库uselesss)

  • 错误恢复是不同的(每个实现都有它自己的一套错误,它可以从恢复)

  • 锁定机制是不同的

  • 在SQL的数据库没有一致的变化情况

  • 嵌套事务

  • 在Model类bleeded默认实现

  • 重新实现所有抽象Queryies是一个大量的工作,推出了很多复制粘贴的bug

  • 没有明确说明的顺序将返回不同的查询订购了不同的实现结果

  • Caching does not know context
  • Cacheimlementation had different semantics
  • batching APIs too different to be abstracted
  • Errors are specific to implementation (e.g. FileNotFound -> FilesearchDialog is uselesss for a tcp/ip based databases)
  • Error recovery is different (each implementation has it's own set of errors it can recover from)
  • locking mechanism was different
  • no consistent change event in SQL-Databases
  • nested transactions
  • default implementation bleeded in Model classes
  • reimplementing all abstracted Queryies was a lot of work and introduced a lot of copy paste bugs
  • querying without explicitly stating the order will return different ordered results in different implementations

我花了很多应用程序的重构:

It took a lot of refactoring of the application:


  • 去掉的功能只有一个实现提供了

  • Cachemanagement每个实施

  • 因为瞬时数据的封装器的身份问题

  • 实施了两个数据存储非常辛苦查询

其他景点:


  • 通过抽象DAL数据的迁移是慢如蜗牛,

  • 实施又一实施不会发生因上述问题实在是太贵了(在提到的场景中,我们开始慢慢重新实现整个项目)

  • 这是极端困难的实施DAL API的语义正确,因为在纯API
  • 没有用的情况下
  • Migration of Data through the abstract DAL is slow as hell
  • implementing yet another implementation will never occur because of the above stated problems it is too expensive (In the mentioned scenario we began to slowly reimplement the whole project)
  • it was extreme difficult to implement the correct semantics of the DAL API because there is no context of use in the pure API

移植(的业务任务),因为我们没有将已经少了很多不好受IMO少数因业绩。

Porting (of business tasks) would have been a lot less painfull IMO as we did that for a few because of performance.

UPDATE2:experience2:路障,同时试图从NHibernate的端口的EntityFramework(implement执行与NH但不能在合理的时间EF 4)

Update2: experience2: RoadBlocks while trying to port from NHibernate to EntityFramework (impl with NH but couldn't with EF 4 in reasonable time)


  • 嵌套事务

  • 支持ENUM

  • 与compositeId引用(如何摆脱referenceIds的)

  • 在组件的引用

  • 阅读配料(期货),这是非常方便的网页+一气呵成计数

  • 映射的CultureInfo(IUserType支持)

这篇关于我怎样才能解决这个NHibernate的查询在N层架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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