Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在NHibernate中强制执行渴望的选择_Nhibernate_Fetching Strategy - Fatal编程技术网

在NHibernate中强制执行渴望的选择

在NHibernate中强制执行渴望的选择,nhibernate,fetching-strategy,Nhibernate,Fetching Strategy,我正在尝试使用selects获取收藏,但我所做的就是 获取是内部连接。发生了什么事 Session.CreateCriteria(typeof(Foo)) .SetFetchMode("Bars", FetchMode.Select) .CreateAlias("Bars", "b") .SetFetchMode("b.Bazes", FetchMode.Select) .List(); 我曾尝试将FetchMode更改为“渴望”,但这不起作用-我 仍然获得内部

我正在尝试使用selects获取收藏,但我所做的就是 获取是内部连接。发生了什么事

Session.CreateCriteria(typeof(Foo))
    .SetFetchMode("Bars", FetchMode.Select)
    .CreateAlias("Bars", "b")
    .SetFetchMode("b.Bazes", FetchMode.Select)
    .List();
我曾尝试将FetchMode更改为“渴望”,但这不起作用-我 仍然获得内部联接,而不是单独选择。我甚至不确定它是从哪里获得内部连接的,因为文档中没有提到FetchMode导致内部连接。 有没有可能得到更多的选择

更新
我发现创建别名会导致内部联接。因此我可以使用.CreateAlias(“bar”,“b”,JoinType.None),但是b.Bazes的获取会恢复为延迟加载。呃。

内部连接是NHibernate加载您的记录及其相关子记录的方式。这通常是最有效的方法

如果要使用多个SELECT语句,那么子查询将需要以某种方式包含父查询的条件。内部连接使得只获取相关子级变得容易,NHibernate将在运行查询后正确地将其拆分为多个实体

我相信Entity Framework 4将允许您执行多个查询并“神奇地”重新附加相关对象,但我不知道NHibernate有这样一个功能(如果我在这方面有错误,我肯定会有人纠正我)。

Session.CreateCriteria(typeof(Foo))
.SetFetchMode(“条”,FetchMode.Select)

.CreateAlias(“bar”,“b”)用于nhibernate加载实体左外连接。因此,您需要如下更改代码:

Session.CreateCriteria(typeof(Foo))
.SetFetchMode("Bars", FetchMode.Select)
.CreateAlias("Bars", "b", JoinType.LeftOuterJoin)
.SetFetchMode("b.Bazes", FetchMode.Select)
.List();

这对我很有帮助

但是默认的连接类型通常是左外连接,不是吗?如果外键可以为null,或者在我的例子中,条可以为空,则内部联接不起作用。此外,文档似乎表明您可以进行快速选择。
Session.CreateCriteria(typeof(Foo))
.SetFetchMode("Bars", FetchMode.Select)
.CreateAlias("Bars", "b", JoinType.LeftOuterJoin)
.SetFetchMode("b.Bazes", FetchMode.Select)
.List();