开发者

Fluent nHibernate QueryOver SQL 'CASE' equivalent

开发者 https://www.devze.com 2023-04-07 06:17 出处:网络
Basically what I want to do is to write this piece of SQL: SELECT CASE WHEN t.ty开发者_StackOverflow社区pe = \'a\' THEN

Basically what I want to do is to write this piece of SQL:

SELECT
CASE
    WHEN t.ty开发者_StackOverflow社区pe = 'a' THEN
        t.name
    ELSE
        t.otherName
    END
    as "Name"
FROM myTable t

in QueryOver


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号