【发布时间】:2010-10-05 16:21:30
【问题描述】:
当我们想通过单次往返急切地加载实体及其子实体时,建议使用 CreateMultiQuery - 返回的列更少,因为我们没有 X*Y*Z*T 而是 X、X*Y、X*Z、X *T。这对我来说效果很好,但它并不是最优的,因为好像 X 是一个有很多列的表,我从数据库中提取了很多数据。示例:
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)";
现在,Feature 表相当大(大约 20 个字段,包括 FK 到其他表)。这意味着对于 query2-5,我得到了大量的数据复制(整个特征字段 + 连接表字段)。
显然,我们需要 FeatureId 以便 Identity Map 可以解析所有内容(整个 Feature 对象及其所有子实体),但为什么它会提取其余部分?
有没有办法对其进行优化,使其仅返回 FeatureId + 连接表列?
【问题讨论】: