当我们想用一个往返来热切加载实体及其子实体时,推荐使用CreateMultiQuery - 由于我们没有X * Y * Z * T而是X,X * Y,X * Z,X * T。这对我来说工作得很好,但它不是最优的,就好像X是一个有许多列的表一样,我从数据库中提取大量数据。例如:进一步优化NHibernate的CreateMultiQuery用法用于提前取用
const string query1 =“select f from Feature f where f.Id in(:fids)”; const string query2 =“select f from Feature f left join fetch f.SprintAssignment where f.Id in(:fids)”; const string query3 =“select f from Feature f left join fetch f.Tasks where f.Id in(:fids)”; const string query4 =“select f from Feature f left join fetch f.Tags where f.Id in(:fids)”; const string query5 =“select f from Feature f inner join fetch f.Project where f.Id in(:fids)”;
现在,功能表是相当大的(大约20个字段,包括FK到其他表)。这意味着对于query2-5,我获得了数据的大量复制(整个特征字段+连接表字段)。
显然,我们需要FeatureId,因此Identity Map可以解析所有东西(整个Feature对象及其所有子实体),但为什么它会解决其余问题?
有没有一种方法来优化它,所以它只会返回FeatureId +连接表列?