Skip to content

Commit 6abcaaf

Browse files
committed
When using .Include against a nullable FK, mapping to the dynamic result causes an exception. Added a guard to ensure dynamic mapping no longer fails when running across a FK that is null.
1 parent d694d0b commit 6abcaaf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

SqlKata.Execution/QueryFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,8 @@ private static IEnumerable<T> handleIncludes<T>(Query query, IEnumerable<T> resu
749749

750750
foreach (var item in dynamicResult)
751751
{
752-
var foreignValue = item[include.ForeignKey].ToString();
753-
item[include.Name] = related.ContainsKey(foreignValue) ? related[foreignValue] : null;
752+
var foreignValue = item[include.ForeignKey]?.ToString();
753+
item[include.Name] = foreignValue != null && related.ContainsKey(foreignValue) ? related[foreignValue] : null;
754754
}
755755
}
756756

0 commit comments

Comments
 (0)