Fluent NHibernate Repository of… integers?
I’d like to preface this by the fact that this “works” doesn’t mean it “should”. If there’s a proper way to do this, I’m all ears.😀
I recently needed to do some revamp to an application that queried lookup data from another data system. The system had a collection of composite keys (age and total score) that returned a percentile score. Easy enough; however, there are a couple dozen of these tables and I didn’t want to create a couple dozen domain objects/repositories for a SINGLE query.
Typically, the NHibernateRepository* takes a type parameter that matches to the mapped object (and provide the proper return type); however, in this case, I didn’t have a type to return, simply an integer. So why wouldn’t that work?
public class ScoreRepository : NHibernateRepository<int>, IDisposable
With that in place, I can now add a query into Session:
public int GetConceptPercentile(int age, int total)
var result =
“select perc from tblConcept where age = :age and total = :total”
A few more of those, and our test looks like:
public void GetPercentiles_For_Student()
using (var repository = new ScoreRepository())
var languagePercentile =
var motorPercentile =
var conceptPercentile =
Everything “appears” to be working; however, the extraneous methods that each NHibernateRepository includes (Get, GetAll, FindAll, etc) are defunct and just sitting there—very messy.
So is there a better way to use NHibernate/Fluent NHibernate WITHOUT mapping objects—those “lookup tables”?