Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluent nHibernate QueryOver SQL 'CASE' equivalent

Basically what I want to do is 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

like image 472
Perpetuum Avatar asked Sep 26 '11 08:09

Perpetuum


1 Answers

maybe there is some nicer syntax possible, 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();
like image 157
Firo Avatar answered Sep 17 '22 11:09

Firo