Fluent nHibernate QueryOver SQL 'CASE' equivalent
Asked Answered
I

1

8

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

Intuit answered 26/9, 2011 at 8:4 Comment(0)
F
7

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();
Fortunio answered 27/9, 2011 at 7:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.