Free nHibernate QueryOver SQL 'CASE' equivalent

Basically, I want to write this piece of SQL:

SELECT CASE WHEN t.type = 'a' THEN t.name ELSE t.otherName END as "Name" FROM myTable t 

in QueryOver

+7
source share
1 answer

there may be a better syntax, but this should do

 var result = session.QueryOver<MyEntity>() .Select(Projections.Alias( Projections.Conditional(Restrictions.Eq("type", 'a'), Projections.Property(t => t.name), Projections.Property(t => t.othername)), "Name" ) .List(); 
+7
source

All Articles