我有以下子/标准:
var sq = DetachedCriteria.For<Title>()
.CreateAlias("Genres", "genre")
.Add(Restrictions.IsNull("genre.ParentId"))
.SetProjection(Projections.Property<Genre>(g=>g.Name));
var q =
session.CreateCriteria(typeof(Title))
.SetProjection(
Projections.Alias(Projections.SqlFunction("array", null, Projections.SubQuery(sq)), "TopLevelGenre"),
Projections.Property<Title>(t1=>t1.Id)
)
.SetMaxResults(5);
这会导致以下 SQL 查询:
SELECT array((SELECT this_0_.title as y0_
FROM title this_0_
inner join title_genre genres3_
on this_0_.title_id = genres3_.title_id
inner join genre genre1_
on genres3_.genre_id = genre1_.genre_id
WHERE genre1_.parent_id is null)) as y0_,
this_.title_id as y1_
FROM title this_
limit 5 /* :p1 */
如何设置它以便我的子查询使用外部查询中的属性值?例如,我希望子查询按 title_id 值过滤。NHibernate 中是否有任何东西允许我将属性值投影到子查询?
谢谢!