leo*_*ora 3 c# nhibernate join fluent-nhibernate fetch
我有一个Person表,其中有许多字段是其他表中的外键
所以我必须做出选择:
References(x => x.Field1).Fetch.Join();
References(x => x.Field2).Nullable().Fetch.Join();
References(x => x.Field3).Nullable().Fetch.Join();
References(x => x.Field4).Nullable().Fetch.Join();
Run Code Online (Sandbox Code Playgroud)
要么
References(x => x.Field1).Fetch.Select();
References(x => x.Field2).Nullable().Fetch.Select();
References(x => x.Field3).Nullable().Fetch.Select();
References(x => x.Field4).Nullable().Fetch.Select();
Run Code Online (Sandbox Code Playgroud)
我看到第一个将对所有其他表进行外连接,而第二个不会.我正在使用nhibernate探查器运行测试,但我试图获得一个经验法则或最佳实践,当你应该使用Fetch.Select()(在网络上找不到很多).
我假设如果我想访问Field2表中的所有条目的另一个字段我最好做前期连接,如果我可能不访问这些关联表中的数据来做第二个
在这个我错过的决定中还有其他因素可以发挥作用吗?
将该决定延迟到用例,因为它有更多的上下文,每个用例都有其他要求.所以:
Join()特殊情况,如多态引用或始终需要引用Fetch(x => x.Fieldx).Eager在查询上使用对特定用例的显式急切加载