How can I solve this NHibernate Querying in an n-tier architecture?
Posted
by
Tyler Wright
on Stack Overflow
See other posts from Stack Overflow
or by Tyler Wright
Published on 2012-10-15T20:33:46Z
Indexed on
2012/10/16
11:01 UTC
Read the original article
Hit count: 316
I've hit a wall with trying to decouple NHibernate from my services layer. My architecture looks like this:
web -> services -> repositories -> nhibernate -> db
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.
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?
© Stack Overflow or respective owner