基本上我想要做的就是编写这段SQL:
SELECT
CASE
WHEN t.type = 'a' THEN
t.name
ELSE
t.otherName
END
as "Name"
FROM myTable t
在QueryOver中
答案 0 :(得分:7)
也许有一些更好的语法可能,但这应该
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();