Zeeshan Ali
Zeeshan Ali

Reputation: 51

Formula in NHibernate Criteria

I would like to add formula to a Projection in NHibernate Criteria:

I have something like this:

Emp Id    Name   Level   Points  
1         Mike   1       50  
2         Jeff   2       100  
3         Steve  3       320  

I would like the results to be ( Level * Points ):

Emp Id    Name   Result  
1         Mike   50     (1*50)
2         Jeff   200    (2*100)
3         Steve  960    (3*320)

This is part of my DetachedCriteria that is why I need this in criteria NOT at entity level. Any other way is welcome as long as it is done using Projections.XXXX(..)

Upvotes: 1

Views: 269

Answers (1)

jjjjj
jjjjj

Reputation: 339

NHibernate doesn't have this functionality out of the box. Here is the implementation of OperatorProjection

If DetachedCriteria API is not so crucial you can translate your DetachedCriteria into Detached QueryOver:

var query = QueryOver.Of<Entity>().Select(x => x.Level * x.Points);

Upvotes: 2

Related Questions