NHibernate QueryOver 按第一个非空值排序(合并)
我试图提出的是这样表达的内容:
var result = Session.QueryOver<Foo>().OrderBy(f => f.UpdatedAt ?? f.CreatedAt);
果然,这行不通。 T-SQL 中大致相当于
... order by coalesce(f.UpdatedAt, f.CreatedAt)
What's the kosher way to do "coalescing" in NHibernate QueryOver?
What I'm trying to come up is something that's expressed like this:
var result = Session.QueryOver<Foo>().OrderBy(f => f.UpdatedAt ?? f.CreatedAt);
Sure enough, this doesn't work. Rough equivalent of this in T-SQL is
... order by coalesce(f.UpdatedAt, f.CreatedAt)
What's the kosher way to do "coalescing" in NHibernate QueryOver?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
迭戈的答案是我想出的方式,但对我来说似乎太冗长了,所以我问 一个问题,并得到一个很好的答案。基本上,您可以注册自己的扩展,然后只需执行
IfNull
是您的新扩展的操作。我什至向 NH Jira 提交了改进提案,但尚未得到回复。Diego's answer is the way I came up with, but it seemed to be too verbose to me, so I asked a question, and got an excellent answer. Basically, you can register your own extensions and then just do
where
IfNull
is your new extension. I've even submitted an improvement proposal to NH Jira, but got no response yet.