Hello,
Before asking this question I have googled for some time, but could not find any relevant information on this topic.
My problem is simple:
I have NHibernate criteria and projection and I'm trying to set DISTINCT ON(column)
My code for projection is following:
criteria.SetProjection(
Projections.ProjectionList()
.Add(Projections.Distinct(Projections.Property("ID")))
.Add(Projections.Property("A"))
.Add(Projections.Property("B"))
);
This generates following SQL (bit simplified):
SELECT DISTINCT ID, A, B FROM ABC ORDER BY A
But unfortunately the performance if this query is very-very poor.
I have optimized my SQL that runs much faster and looks like this:
SELECT DISTINCT ON (A) ID, A, B FROM ABC ORDER BY A
Is there anyway I can make NHibernate generate SQL that I have just shown? Is this problem solvable with NHibernate's dialects?
Looking forward to Your feedback! Thank You very much!