Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Proposal: nhibernate support #401

Open
Geestarraw opened this issue Jun 4, 2024 · 3 comments
Open

Feature Proposal: nhibernate support #401

Geestarraw opened this issue Jun 4, 2024 · 3 comments

Comments

@Geestarraw
Copy link

Hi!
Love the specification pattern and this package and wonder if there has been any thoughts, attempts or plans of starting to support nhibernate as well?

Best regards

@JimmyAtSchotte
Copy link

I’m currently working on a project that uses NHibernate instead of Entity Framework, and I’ve found that the built-in LINQ-to-Query capabilities integrate well with this package. I’ve developed my own Repository, SpecificationEvaluator, and FetchEvaluator, while making use of the existing Where, OrderBy, and Pagination evaluators.

However, implementing NHibernate’s Criteria API has been more complex. I managed to create a proof of concept by building my own Criteria API as an adapter between the Specification pattern and the evaluators. I also extended the ISpecification interface to store and retrieve criteria using the Items object.

In this proof of concept, I even got the Criteria API to work with Entity Framework by generating expression trees that could interact with IQueryable.

While it’s feasible to implement the Criteria API, I’m concerned that developing a fully supported version could require a significant amount of time, especially if it needs to work with both NHibernate and Entity Framework.

@fiseni
Copy link
Collaborator

fiseni commented Sep 10, 2024

Generally, we have nothing against adding support for NHibernate.
I personally do not use NHibernate, so I don't think I'll invest time in it. But we'd welcome a contribution, and we'll provide help with the implementations if necessary.

We tried to make the infrastructure as flexible as possible and I believe it's easy to add/replace evaluators. If you need anything else in that regard let us know.

@JimmyAtSchotte
Copy link

I wrote a blog post on how I extended Ardalis.Specification to support NHibernate (Linq-to-query, Criteria, QueryOver).

You can find examples in this demo repository.

I did some "cheating" by directly referencing the Criteria and QueryOver APIs in my custom Specification classes. Initially, I considered creating an abstraction layer above these APIs, but that would have required writing a lot of extra code!

The downside of this approach is that if there’s ever a need to transition from NHibernate to Entity Framework Core, any specifications written using Criteria or QueryOver will need to be rewritten using Linq.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants