开发者

NHibernate QueryOver with nested select in FROM

开发者 https://www.devze.com 2023-04-05 18:07 出处:网络
How would you write t开发者_JAVA技巧he following using QueryOver (or CriteriaAPI for that matter)?

How would you write t开发者_JAVA技巧he following using QueryOver (or CriteriaAPI for that matter)?

select foo from (select 1 as foo) as bar


This is actually not totally obvious if you use the QueryOver interface - which is more complex and subtle than it first appears. Consider using NHibernate.Linq.LinqExtensionMethods.Query<T>:

session.Query<Person>().Select(p => p.Husband).Select(p => p.Name).ToList()

Will give you a List<string>, corresponding to the sql:

select h.name from (select husband as h from person) as h
0

精彩评论

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

关注公众号