Skip to content

Commit 50078f0

Browse files
committed
Simplify code. Fix comment. Cleanup whitespaces
1 parent 72ee45c commit 50078f0

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/NHibernate/Cache/StandardQueryCache.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ private static long GetResultsMetadata(IList cacheable, out string[] aliases)
410410
}
411411

412412
private static bool IsEmpty(IList cacheable)
413-
// First element is the timestamp.
413+
// First element is metadata.
414414
=> cacheable.Count <= 1;
415415

416416
private static IEnumerable<object> GetResultsEnumerable(IList cacheable)
@@ -427,18 +427,13 @@ private static ICacheAssembler[] GetReturnTypes(
427427
ICacheAssembler[] returnTypes,
428428
IList cacheable)
429429
{
430-
var hasResults = !IsEmpty(cacheable);
431-
if (key.ResultTransformer?.AutoDiscoverTypes == true && hasResults)
432-
{
433-
returnTypes = GuessTypes(cacheable);
434-
}
430+
if (IsEmpty(cacheable))
431+
return returnTypes;
435432

436-
if (hasResults && returnTypes == null)
437-
{
438-
throw new HibernateException("Return types for non empty query results are null, cannot assemble the results");
439-
}
433+
if (key.ResultTransformer?.AutoDiscoverTypes == true)
434+
returnTypes = GuessTypes(cacheable);
440435

441-
return returnTypes;
436+
return returnTypes ?? throw new HibernateException("Return types for non empty query results are null, cannot assemble the results");
442437
}
443438

444439
private static void PerformBeforeAssemble(
@@ -621,17 +616,20 @@ private static ICacheAssembler[] GuessTypes(IList cacheable)
621616
foundTypes++;
622617
}
623618
}
619+
624620
if (foundTypes == colCount)
625621
break;
626622
}
627623
}
624+
628625
// If a column value was null for all rows, its type is still null: put a type which will just yield null
629626
// on null value.
630627
for (var i = 0; i < colCount; i++)
631628
{
632629
if (returnTypes[i] == null)
633630
returnTypes[i] = NHibernateUtil.String;
634631
}
632+
635633
return returnTypes;
636634
}
637635

0 commit comments

Comments
 (0)