我使用子查询获得以下NHibernate查询:
NHContext.Session.QueryOver<Item>()
.WithSubquery.WhereProperty(x => x.ItemId).In(QueryOver.Of<Foo>().Where(x => x.AFlag).Select(x => x.ItemId))
.WithSubquery.WhereProperty(x => x.ItemId).In(QueryOver.Of<Bar>().Where(x => x.AFlag).Select(x => x.Item))
.Future<Item>();
Run Code Online (Sandbox Code Playgroud)
这将运行以下SQL:
SELECT *
FROM item this_
WHERE this_.ItemId in (SELECT this_0_.ItemId as y0_
FROM Foo this_0_
WHERE this_0_.AFlag = 1 /* @p0 */)
and this_.ItemId in (SELECT this_0_.ItemId as y0_
FROM Bar this_0_
WHERE this_0_.AFlag = 1 /* @p0 */)
Run Code Online (Sandbox Code Playgroud)
我希望它使用OR,例如:
SELECT *
FROM item this_
WHERE this_.ItemId in (SELECT this_0_.ItemId as y0_
FROM Foo this_0_
WHERE this_0_.AFlag = 1 /* …Run Code Online (Sandbox Code Playgroud) 有没有办法在使用QueryOver或ICriteria查询时在NHibernate中指定外连接的附加条件?
我在外连接表上需要一些额外的条件,但是NHibernate总是将它们添加到最后的WHERE子句中 - 这没有得到正确的行为(参见http://weblogs.sqlteam.com/jeffs/archive/2007) /05/14/criteria-on-outer-joined-tables.aspx).
我似乎无法使用Criteria或QueryOver语法找到任何方法...
谢谢